1 PackageisPowerOfThree326;2 /*3 Given An integer, write a function to determine if it is a power of three.4 */5 Public classSolution {6 /*7 //The problem is understood incorrectly and understood as 3 times8 Public Static Boolean ispowerofthree (int n) {9 if (n==1)Ten return true; One else{ A for (int i=2;i<=math.sqrt (n); i++) { - if (n%i==0) { - n=n/i; the if (n%i==0) { - n=n/i; - if (n%i==0) { - n=n/i; + return Ispowerofthree (n); - } + Else A return false; at } - return false; - } - } - return false; - } in } - */ to Public Static BooleanIspowerofthree (intN) { + if(n==1) - return true; the Else if(n==0) * return false; $ Else if(n%3==0){Panax NotoginsengN=n/3; - returnispowerofthree (n); the } + Else A return false; the + - } $ Public Static voidMain (string[] args) { $ //TODO auto-generated Method Stub -System.out.println (Ispowerofthree (-3)); - } the -}
Leetcode----326. Power of three (Java)