17 Binary Search

2分模板:

L458 Last Position of Target

L14 First Position of Target

L462 Total Occurrence of Target

普通2分:

74 Search in a 2D Matrix (L28)

240 Search in a 2D matrix II (L38)

162 Find Peak Element (L75)

L390 Find Peak Element II

L585 maximum Number in Mountain Sequence

278 First Bad Version (L74)

35 Search Insert Position (L60)

L447 Search in a Big Sorted Array (702)

L459 Closest Number in Sorted Array

L460 K closest Numbers in Sorted Array

744 Find Smallest Letter Greater Than Target

1064 Fixed Point

1228 Missing Number In Arithmetic Progression

528 Random Pick with Weight

L194 Find Words

复杂一点的2分搜索:

Rotate Arrays

540 Single Element in a Sorted Array

34 Search for a Range (L61)

302 Smallest Rectangle Enclosing Black Pixels - 还可以用bfs,不过2分比较好 (L600)

275 H-Index II -- 九章模板套不了,二分终极版

L824 Single Number IV

1539 Kth Missing Positive Number -- 九章模板套不了,好像那些答案不在中间的都挺难套九章二分的

1712 Ways to Split Array Into Three Subarrays

二分答案:这种题的 T:O(nlog(answer range)),只能用于答案range是连续而且有一个分界点。写法:一个用来筛选答案的2分函数,在主函数里调用这个函数2分地找。

287 Find the Duplicate number -- 竟然还能用142 Linked List Cycle II的解法

367 Valid Perfect Square

374 Guess Number Higher or Lower

L437 copy books I - can also use DP

L438 copy books II - can also use DP

410 Split Array Largest Sum - can also use DP

pramp mock test 2,grant cut

L141 Sqrt(x) (69)

RootOfNumber -- pramp,进化版的L586 Sqrt(x) II

L183 Wood Cut

L254 Drop Egg - ctci 6.8

L617 maximum Average Subarray

881 Boats to Save People

1631 Path With Minimum Effort

441 Arranging Coins

875 Koko Eating Bananas

878 Nth Magical Number

与树相关的2分:

222 Count Complete Tree Nodes

230 Kth Smallest Element in a BST

270 Closest Binary Search Tree Value - pramp 3 - TreeSet flooring / celing / lower / higher

Other related:

375 Guess Number Higher or Lower II - DP or MiniMax

L586 Sqrt(x) II --- 牛顿法

L584 Drop Eggs II -- DP

感觉比较难的二分?:

4 Median of Two Sorted Arrays - 与230有点像

Last updated