refactor: refactor project structure
This commit is contained in:
21
legacy/326 isPowerOfThree/C#/Program.cs
Executable file
21
legacy/326 isPowerOfThree/C#/Program.cs
Executable file
@@ -0,0 +1,21 @@
|
||||
public class Solution {
|
||||
public bool IsPowerOfThree(int n) {
|
||||
if(n <= 0)
|
||||
return false;
|
||||
if(n == 1)
|
||||
return true;
|
||||
if(n % 3 != 0)
|
||||
return false;
|
||||
return IsPowerOfThree(n/3);
|
||||
}
|
||||
}
|
||||
|
||||
class program{
|
||||
static void Main(){
|
||||
var Solution = new Solution();
|
||||
|
||||
Console.WriteLine(Solution.IsPowerOfThree(9));
|
||||
Console.WriteLine(Solution.IsPowerOfThree(0));
|
||||
Console.WriteLine(Solution.IsPowerOfThree(-1));
|
||||
}
|
||||
}
|
10
legacy/326 isPowerOfThree/C#/isPowerOfThree.csproj
Executable file
10
legacy/326 isPowerOfThree/C#/isPowerOfThree.csproj
Executable file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
22
legacy/326 isPowerOfThree/description.md
Executable file
22
legacy/326 isPowerOfThree/description.md
Executable file
@@ -0,0 +1,22 @@
|
||||
Given an integer n, return true if it is a power of three. Otherwise, return false.
|
||||
|
||||
An integer n is a power of three, if there exists an integer x such that n == 3x.
|
||||
|
||||
|
||||
|
||||
Example 1:
|
||||
|
||||
Input: n = 27
|
||||
Output: true
|
||||
Explanation: 27 = 33
|
||||
Example 2:
|
||||
|
||||
Input: n = 0
|
||||
Output: false
|
||||
Explanation: There is no x where 3x = 0.
|
||||
Example 3:
|
||||
|
||||
Input: n = -1
|
||||
Output: false
|
||||
Explanation: There is no x where 3x = (-1).
|
||||
|
26
legacy/326 isPowerOfThree/go/app.go
Executable file
26
legacy/326 isPowerOfThree/go/app.go
Executable file
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Solution struct{}
|
||||
|
||||
func (s Solution) IsPowerOfThree(n int) bool{
|
||||
if n <= 0{
|
||||
return false
|
||||
}
|
||||
if n == 1{
|
||||
return true
|
||||
}
|
||||
if n % 3 != 0{
|
||||
return false
|
||||
}
|
||||
return s.IsPowerOfThree(n/3)
|
||||
}
|
||||
|
||||
func main(){
|
||||
solution := Solution{}
|
||||
|
||||
fmt.Println(solution.IsPowerOfThree(27))
|
||||
fmt.Println(solution.IsPowerOfThree(0))
|
||||
fmt.Println(solution.IsPowerOfThree(-1))
|
||||
}
|
Reference in New Issue
Block a user