My C++ solution


  • 0
    P

    I find that using stoll faster than stoul, and I don't know why

    class Solution {
    public:
        uint32_t reverseBits(uint32_t n) {
            string s(32, '0');
    	    int i = 0;
    	    while (n){
    		    s[i++] = '0'+n % 2;
    		    n /= 2;
    	    }
    	    return stoul(s, 0, 2);
        }
    };

Log in to reply
 

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