[리트코드] 278. First Bad Version




278. First Bad Version

리트코드

나의 풀이

/**
 * @param {function} isBadVersion()
 * @return {function}
 */
var solution = function (isBadVersion) {
  /**
   * @param {integer} n Total versions
   * @return {integer} The first bad version
   */
  return function (n) {
    let start = 1;
    let end = n;
    while (start <= end) {
      let mid = Math.floor((start + end) / 2);
      isBadVersion(mid) ? (end = mid - 1) : (start = mid + 1);
    }
    return start;
  };
};

Runtime: 91 ms, faster than 30.52% of JavaScript online submissions for First Bad Version.