Short C++ solution, 0ms


  • 2
    T
    // Forward declaration of isBadVersion API.
    bool isBadVersion(int version);
    
    class Solution {
    public:
        int firstBadVersion(int n) {
            int step = (1<<30), j;
            for(j=0;step;step>>=1)
                if(j+step<=n && !isBadVersion(j+step)) j+=step;
            return j+1;
        }
    };

Log in to reply
 

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