feat : add go solution with problem 326
This commit is contained in:
26
202508/326 isPowerOfThree/go/app.go
Normal file
26
202508/326 isPowerOfThree/go/app.go
Normal 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