Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第一个错误的版本 #353

Open
lzxjack opened this issue Jan 11, 2023 · 1 comment
Open

第一个错误的版本 #353

lzxjack opened this issue Jan 11, 2023 · 1 comment

Comments

@lzxjack
Copy link
Contributor

lzxjack commented Jan 11, 2023

No description provided.

@lzxjack
Copy link
Contributor Author

lzxjack commented Jan 12, 2023

const solution = isBadVersion => n => {
  let [left, right] = [1, n];

  // 假设n是第一个错误版本
  let res = n;
  while (left <= right) {
    const mid = (left + right) >>> 1;
    if (isBadVersion(mid)) {
      // 更新res
      res = mid;
      // 找下一个可能的
      right = mid - 1;
    } else {
      left = mid + 1;
    }
  }
  return res;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant