374. Guess Number Higher or Lower - Easy 前往題目 想法 就是最基本的Binary Search 思路同想法 Codepublic class Solution extends GuessGame { public int guessNumber(int n) { // 1 ~ n int l = 1, r = n; while (l <= r) { int mid = l + (r - l) / 2; // Found if (guess(mid) == 0) { return mid; } else if (guess(mid) == -1) { r = mid - 1; } else { l = mid + 1; } } return 0; } } Leetcode. Easy #Leetcode #心得 #Binary Search #Interactive 374. Guess Number Higher or Lower - Easy https://f88083.github.io/2024/09/16/374-Guess-Number-Higher-or-Lower-Easy/ 作者 Simon Lai 發布於 2024年9月16日 許可協議 1898. Maximum Number of Removable Characters - Medium 上一篇 162. Find Peak Element - Medium 下一篇 Please enable JavaScript to view the comments