From dc2b691d894678944ee75fe0db3d1cbfb23b332d Mon Sep 17 00:00:00 2001 From: Eziox69 <106980196+Eziox69@users.noreply.github.com> Date: Fri, 28 Oct 2022 22:48:55 +0530 Subject: [PATCH] Create LEETCODE First best version.cpp --- LEETCODE First best version.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 LEETCODE First best version.cpp 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; + + } +};