diff --git a/LEETCODE First best version.cpp b/LEETCODE First best version.cpp new file mode 100644 index 0000000..471bce2 --- /dev/null +++ b/LEETCODE First best version.cpp @@ -0,0 +1,20 @@ +class Solution { +public: + int firstBadVersion(int n) { + + int s =1; + int e =n; + int ans =n; + while(s<=e){ + int mid = (s-e)/2+e; + if(isBadVersion(mid)){ + ans = mid; + e = mid-1; + }else{ + s = mid+1; + } + } + return ans; + + } +};