Using (start + n/2) condition!


  • 0
    L
    class Solution {
    public:
    int firstBadVersion(int n, int s=1) {
    
    int mid = s+ n/2;
    
    if(n/2 == 0) 
    {
        if(isBadVersion(mid)) return mid;
        else if( n >=2) return mid+1;
    }
    
    if(isBadVersion(mid))  
        firstBadVersion(n/2,s);
    else 
        firstBadVersion(n/2,mid+1);
    }
    

    };


Log in to reply
 

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