My simple O(lgN) ten lines C# code


  • 0
    M
        public int FirstBadVersion(int n) {
                int lo = 1;
                int hi = n;
                while (lo < hi)
                {
                    int mid = lo + (hi - lo) / 2;
                    if (IsBadVersion(mid))
                        hi = mid;
                    else
                        lo = mid + 1;
                }
                return hi;
        }
    

Log in to reply
 

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