My Stupid Bruteforce Solution


  • -9
    G
    class Solution {
    public:
        int arr[50] = {
            1,
            2,
            4,
            8,
            16,
            32,
            64,
            128,
            256,
            512,
            1024,
            2048,
            4096,
            8192,
            16384,
            32768,
            65536,
            131072,
            262144,
            524288,
            1048576,
            2097152,
            4194304,
            8388608,
            16777216,
            33554432,
            67108864,
            134217728,
            268435456,
            536870912,
            1073741824
        };
        bool isPowerOfTwo(int n) {
            for (int i = 0; i < 31; i++)
                if (arr[i] == n) return true;
            return false;
        }
    };

  • 0
    W

    that's a plan!


  • 0
    V

    gooooooooooooooooooooooooooooooooood job!


  • 0
    H

    you can save it in a set beforehand and then, no need to check 31 times in the main function.... one check is sufficient


  • 0
    G

    oooooooooooooooo
    omg..


Log in to reply
 

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