You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/**326. Power of Three QuestionEditorial Solution My Submissions
3
+
Total Accepted: 57555
4
+
Total Submissions: 151383
5
+
Difficulty: Easy
6
+
Given an integer, write a function to determine if it is a power of three.
7
+
8
+
Follow up:
9
+
Could you do it without using any loop / recursion?
10
+
11
+
*/
12
+
13
+
publicclassPowerOfThree {
14
+
//it turns out they're using a trick to solve this question without using a loop: find the max possible integer that is a power of 3, then do modulor with this number
15
+
publicbooleanisPowerOfThree_without_loop(intn) {
16
+
return (n > 0 && 1162261467 % n == 0);
17
+
}
18
+
19
+
//I'm not able to think of a method that has no loop to do it, use regular method to solve it first
0 commit comments