Problem Solving/LeetCode
Today's Challenge
fabichoi
2022. 8. 8. 23:45
https://leetcode.com/problems/longest-increasing-subsequence/
Longest Increasing Subsequence - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
조금은 신박한 방법으로 문제를 풀어낸 솔루션 참고.
근데 그 소스에는 bisect_left를 사용했는데, 내가 알기론 bisect 관련 함수는 정렬이 돼있어야 되는 걸로 알아서
의도에 맞게 내 식대로 변경함
class Solution:
def lengthOfLIS(self, nums: List[int]) -> int:
arr = [nums.pop(0)]
for num in nums:
if num > arr[-1]:
arr.append(num)
else:
for i in range(len(arr)):
if arr[i] >= num:
arr[i] = num
break
return len(arr)
반응형