JavaScript solution


  • 0
    L
    function solution(isBadVersion) {
      return function(n) {
        var left = 0;
        var right = n;
    
        while (right - left !== 1) {
          var mid = parseInt((left + right) / 2);
    
          if (isBadVersion(mid)) {
            right = mid;
          } else {
            left = mid;
          }
        }
        return right;
      };
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.