Dealing with Integer's maximum value


  • 1
    S

    How can the input be 2^32 when int's only go from -(2^31) to (2^31 - 1)? I understand the problem deals with unsigned ints, but my code is failing when the input is 2^31, and I think my logic is fine? How is 2^31 even allowed to be an input when int's are assumed to be signed in java?

    int count = 0;
    while(n > 0) {
         n = (n & (n-1));
         count++;
    }
    return count;
    

Log in to reply
 

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