提交 b5568f5f 编写于 作者: M Mars Liu

fixed code bug in check

上级 d4c79d48
...@@ -27,7 +27,7 @@ int check(int x) { ...@@ -27,7 +27,7 @@ int check(int x) {
if(x < 2){ if(x < 2){
return 0; return 0;
} }
return x & (x-1) == 0; return (x & (x-1)) == 0;
} }
``` ```
...@@ -38,11 +38,31 @@ int check(int x) { ...@@ -38,11 +38,31 @@ int check(int x) {
```c ```c
bool check(int x) { int check(int x) {
if(x < 2){ return (x & (x-1)) == 0;
return 0; }
}
```
### 优先级错误
```c
int check(int x) {
return x & (x-1) == 0; return x & (x-1) == 0;
} }
``` ```
### 边界条件处理的不对
```c
int check(int x) {
for(int value = x; value > 0; value = value/2) {
if((value % 2) != 0){
return 0;
}
}
return 1;
}
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册