Error in Power of Two question


  • 0
    E

    I just wrote a solution to the "Power of Two" problem, in C++:

    class Solution {
    public:
        bool isPowerOfTwo(int n) {
            return n != 0 && (n == 1 || !(n & (n - 1)));
        }
    };
    

    This was rejected with the error being that -2147483648 should be a power of two. Wat.

    Submitting

    class Solution {
    public:
        bool isPowerOfTwo(long long n) {
            return n != 0 && (n == 1 || !(n & (n - 1)));
        }
    };
    

    makes it pass. But the question comes with an int parameter filled in. I think this is an error in the question.


  • 0

    @eckerdal Next time please post in the correct category. I have moved this to the correct category.


Log in to reply
 

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