/**
* Definition for isBadVersion()
*
* @param {integer} version number
* @return {boolean} whether the version is bad
* isBadVersion = function(version) {
* ...
* };
*/
/**
* @param {function} isBadVersion()
* @return {function}
*/
var solution = function (isBadVersion) {
return function (n) {
let left = 0,
right = n - 1;
while (left <= right) {
const mid = left + Math.floor((right - left) / 2);
if (isBadVersion(mid)) right = mid - 1;
else left = mid + 1;
}
return left;
};
};
GitHub : https://github.com/developeSHG/Algorithm-LeetCode/tree/main/first-bad-version
'Coding Test > LeetCode' 카테고리의 다른 글
[LeetCode] (Math) Lv Easy. Fizz Buzz (0) | 2023.01.22 |
---|---|
[LeetCode] (Dynamic Programming) Lv Easy. Climbing Stairs (0) | 2023.01.22 |
[LeetCode] (Sorting and Searching) Lv Easy. Merge Sorted Array (0) | 2023.01.22 |
[LeetCode] (Trees) Lv Easy. Maximum Depth of Binary Tree (0) | 2023.01.21 |
[LeetCode] (Linked List) Lv Easy. Delete Node in a Linked List (0) | 2023.01.16 |
댓글