Skip to content

Commit 0ae1431

Browse files
committed
feat(#300): add binary search solution
1 parent 5ff126f commit 0ae1431

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

300.Longest Increasing Subsequence/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,29 @@ func max(a, b int) int {
5151
return b
5252
}
5353
```
54+
55+
binary search
56+
57+
```golang
58+
func lengthOfLIS(nums []int) int {
59+
var piles int
60+
top := make([]int, len(nums))
61+
for _, pocker := range nums {
62+
left, right := 0, piles
63+
for left < right {
64+
mid := left + (right - left) / 2
65+
if top[mid] >= pocker {
66+
right = mid
67+
} else {
68+
left = mid + 1
69+
}
70+
}
71+
if left == piles {
72+
piles++
73+
}
74+
top[left] = pocker
75+
}
76+
77+
return piles
78+
}
79+
```

0 commit comments

Comments
 (0)