본문 바로가기
Coding Test/LeetCode

[LeetCode] (Sorting and Searching) Lv Easy. First Bad Version

by song.ift 2023. 1. 22.

https://leetcode.com/explore/interview/card/top-interview-questions-easy/96/sorting-and-searching/774/

 

Explore - LeetCode

LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore.

leetcode.com

 

javascript
닫기
/** * 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

 

GitHub - developeSHG/Algorithm-LeetCode: 릿코드 소스코드

릿코드 소스코드. Contribute to developeSHG/Algorithm-LeetCode development by creating an account on GitHub.

github.com

 

댓글