Created
March 8, 2017 06:56
-
-
Save csujedihy/07d8c7fc917fedff618a0f9774c0b45f to your computer and use it in GitHub Desktop.
LIS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution(object): | |
def lengthOfLIS(self, nums): | |
""" | |
:type nums: List[int] | |
:rtype: int | |
""" | |
tail = [] | |
for i in xrange(0, len(nums)): | |
idx = bisect.bisect_right(tail, nums[i]) | |
if idx - 1 >= 0 and nums[i] == tail[idx - 1]: | |
continue | |
if idx == len(tail): | |
tail.append(nums[i]) | |
else: | |
tail[idx] = nums[i] | |
return len(tail) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment