File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * @lc app=leetcode id=326 lang=java
3
+ *
4
+ * [326] Power of Three
5
+ *
6
+ * https://leetcode.com/problems/power-of-three/description/
7
+ *
8
+ * algorithms
9
+ * Easy (41.40%)
10
+ * Total Accepted: 178.1K
11
+ * Total Submissions: 428.8K
12
+ * Testcase Example: '27'
13
+ *
14
+ * Given an integer, write a function to determine if it is a power of three.
15
+ *
16
+ * Example 1:
17
+ *
18
+ *
19
+ * Input: 27
20
+ * Output: true
21
+ *
22
+ *
23
+ * Example 2:
24
+ *
25
+ *
26
+ * Input: 0
27
+ * Output: false
28
+ *
29
+ * Example 3:
30
+ *
31
+ *
32
+ * Input: 9
33
+ * Output: true
34
+ *
35
+ * Example 4:
36
+ *
37
+ *
38
+ * Input: 45
39
+ * Output: false
40
+ *
41
+ * Follow up:
42
+ * Could you do it without using any loop / recursion?
43
+ */
44
+ class Solution {
45
+ public boolean isPowerOfThree (int n ) {
46
+ if (n < 1 ) return false ;
47
+ while (n % 3 == 0 ) {
48
+ n /= 3 ;
49
+ }
50
+ return n == 1 ;
51
+ }
52
+ }
53
+
You can’t perform that action at this time.
0 commit comments