Can anyone tell me what's wrong with my C++ code?


  • 0
    S
    class solution{
    public:
        int findComplement(int num){
            int i;
            for(i=31;i>=0;i--){
                int mask=1<<i;
                if(num&mask)break;
            }
            for(;i>=0;i--){
                int mask=1<<i;
                num^=mask;
            }
            return num;
        }
    };
    

    For the test case 20161211, it outputs 0. But I don't know why it outputs that. What's wrong with my code?
    Follow up:
    I test it in my own computer and it outputs the correct result for 20161211. So I think there is something tricky with the judging process...


  • 0
    G

    The same thing happend to me!
    20161211


  • 0

    Hi @sanxi,

    Sorry for the inconvenience of wrong test-case showing, we are working on solving this problem.

    Please wait for a more moment, we'll give you a satisfying answer.

    Best,
    Leetcode Team


  • 0

    Hi @sanxi,

    Truly sorry for your trouble, we just found one of our server hasn't been synchronized with newest test cases because of some hardware reasons.

    So, you could see most users got AC for this problem but some users got WA indescribably.

    We'll rejudge all the submission again immediately and you'll see the newest results afterward, thanks for your feedback.

    Best,
    Leetcode Team.


  • 0

    @sanxi All problem 1 submissions were rejudged, your code should pass the judge.


  • 0
    S

    @love_FDU_llp @1337c0d3r OK. Thanks.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.