Skip to content

Instantly share code, notes, and snippets.

@ahmet-cetinkaya
Created December 29, 2020 19:24
Show Gist options
  • Save ahmet-cetinkaya/5a63e8c8bc905fd1ecc5739376a99540 to your computer and use it in GitHub Desktop.
Save ahmet-cetinkaya/5a63e8c8bc905fd1ecc5739376a99540 to your computer and use it in GitHub Desktop.
LeetCode Solution 278. First Bad Version
const solution = (isBadVersion) => (n) => {
let left = 1,
right = n;
while (left < right) {
const middle = Math.floor(left + (right - left) / 2);
if (isBadVersion(middle)) right = middle;
else left = middle + 1;
}
return left;
};
@ahmet-cetinkaya
Copy link
Author

Result
Runtime: 76 ms, faster than 70.43% of JavaScript online submissions for First Bad Version.
Memory Usage: 38.4 MB, less than 53.14% of JavaScript online submissions for First Bad Version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment