未验证 提交 d9824e21 编写于 作者: K Keqi Huang 提交者: GitHub

Update 300._longest_increasing_subsequence.md

上级 6d8e3ce5
......@@ -76,14 +76,14 @@ class Solution(object):
:type nums: List[int]
:rtype: int
"""
def binarySearch(nums, l, r, key):
while l < r-1:
mid = l + (r - l)//2
if (nums[mid] >= key):
r = mid
def binarySearch(nums, l, r, target):
while l <= r:
mid = l + ((r-l) >> 1)
if nums[mid] < target:
l = mid + 1
else:
l = mid
return r
r = mid - 1
return l
if not nums or len(nums) == 0:
return 0
......@@ -106,7 +106,7 @@ class Solution(object):
# end candidate of an existing
# subsequence. It will replace
# ceil value in tailTable
tails[binarySearch(tails, -1, length-1, nums[i])] = nums[i]
tails[binarySearch(tails, 0, length-1, nums[i])] = nums[i]
return length
```
......@@ -114,7 +114,7 @@ class Solution(object):
> 思路 2
调用自带的二分
调用自带的二分,并且不维护整个tails,只是慢慢往上面append元素,这样二分查找时不需要手动输入left和right
```python
class Solution(object):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册