二分搜尋 Binary Search
37 題(22 題以此為主技法)
🎯 何時用
在有序(或局部有序、旋轉)陣列中找目標/邊界。
🧩 模板心法
維持搜尋區間不變式,依中點與目標關係收斂;找邊界用 lower/upper bound 寫法避免漏邊界。
Easy 6 題
Medium 24 題
- #33Search in Rotated Sorted Array
- #153Find Minimum in Rotated Sorted Array
- #300Longest Increasing Subsequence
- #167Two Sum II - Input Array Is Sorted
- #240Search a 2D Matrix II
- #34Find First and Last Position of Element in Sorted Array
- #74Search a 2D Matrix
- #81Search In Rotated Sorted Array II
- #162Find Peak Element
- #540Single Element in a Sorted Array
- #673Number of Longest Increasing Subsequence
- #2300Successful Pairs of Spells and Potions
- #209Minimum Size Subarray Sum
- #875Koko Eating Bananas
- #981Time Based Key-Value Store
- #528Random Pick with Weight
- #658Find K Closest Elements
- #1011Capacity to Ship Packages Within D Days
- #1268Search Suggestions System
- #1631Path with Minimum Effort
- #1838Frequency of The Most Frequent Element
- #1898Maximum Number of Removable Characters
- #2439Minimize Maximum of Array
- #2616Minimize the Maximum Difference of Pairs