We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7e478ce commit 9fd2403Copy full SHA for 9fd2403
231_power-of-two.cpp
@@ -0,0 +1,47 @@
1
+class Solution {
2
+public:
3
+ bool isPowerOfTwo(int n) {
4
+ if (n <= 0) {
5
+ return false;
6
+ }
7
+ for (; n != 1; n >>= 1) {
8
+ if (n & 0 != 1) {
9
10
11
12
+ return true;
13
14
+};
15
+
16
17
+/*
18
+// CodeHelp Solution:
19
20
+#include<limits.h>
21
22
23
24
25
26
+ int ans = 1;
27
28
+ for(int i = 0; i <= 30; i++) {
29
30
+ //cout<<" ans "<<ans <<endl;
31
+ if(ans == n)
32
+ {
33
34
35
+ if(ans < INT_MAX/2)
36
+ ans = ans * 2;
37
38
39
40
41
42
+*/
43
44
45
+// Explation of the efficiency from ChatGPT
46
+https://chatgpt.com/share/a3481a36-6a40-48f4-98cf-39e92f34f545
47
0 commit comments