We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent cb39658 commit 3418746Copy full SHA for 3418746
PowerOfTwo.java
@@ -0,0 +1,26 @@
1
+public class PowerOfTwo {
2
+
3
+ // 반복문 사용
4
+ public boolean isPowerOfTwo(int n) {
5
+ if (n <= 0) return false;
6
+ if (n == 1) return true;
7
+ while (n > 1) {
8
+ if (n % 2 == 1)
9
+ return false;
10
+ n /= 2;
11
+ }
12
+ return true;
13
14
15
+ /*
16
+ // 재귀 사용
17
18
19
+ if(n==1) return true ;
20
+ else if ( n%2==1 || n==0 ) return false ;
21
22
+ return isPowerOfTwo(n/2);
23
24
25
+ */
26
+}
0 commit comments