当前位置:网站首页>leetcode 278. First wrong version

leetcode 278. First wrong version

2022-06-12 06:22:00 Well, let me see

278. First wrong version
 Please add a picture description

Thought analysis :
Binary search template !

AC Code :

class Solution {
    
public:
    int firstBadVersion(int n) {
    
        int l = 1, r = n;
        while(l < r) {
    
            int mid = (long long)l + r >> 1;
            if(isBadVersion(mid)) r = mid;
            else l = mid + 1;
        }
        return r;
    }
};
原网站

版权声明
本文为[Well, let me see]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203010610049986.html