From b5568f5f33a0ef99b862ba4a9da2d1ed5f670f98 Mon Sep 17 00:00:00 2001 From: Mars Liu Date: Thu, 21 Oct 2021 17:08:25 +0800 Subject: [PATCH] fixed code bug in check --- .../check.md" | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/3.\344\275\215\350\277\220\347\256\227/1.\344\275\215\345\222\214\345\255\227\350\212\202/check.md" "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/3.\344\275\215\350\277\220\347\256\227/1.\344\275\215\345\222\214\345\255\227\350\212\202/check.md" index fbcd09f..059c793 100644 --- "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/3.\344\275\215\350\277\220\347\256\227/1.\344\275\215\345\222\214\345\255\227\350\212\202/check.md" +++ "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/3.\344\275\215\350\277\220\347\256\227/1.\344\275\215\345\222\214\345\255\227\350\212\202/check.md" @@ -27,7 +27,7 @@ int check(int x) { if(x < 2){ return 0; } - return x & (x-1) == 0; + return (x & (x-1)) == 0; } ``` @@ -38,11 +38,31 @@ int check(int x) { ```c -bool check(int x) { - if(x < 2){ - return 0; - } +int check(int x) { + return (x & (x-1)) == 0; +} + +``` + +### 优先级错误 + +```c + +int check(int x) { 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 -- GitLab