https://leetcode.com/problems/longest-increasing-subsequence/
DP 문제
2개의 for문을 써서 기존의 longest increasing sequence를 활용한다.
class Solution(object):
def lengthOfLIS(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
if not nums:
return 0
dp_arr = [ 1 for i in range(len(nums)) ]
for j in range(0, len(nums), 1):
for i in range(j+1, len(nums), 1):
if nums[i] > nums[j]:
dp_arr[i] = max(dp_arr[i], dp_arr[j] + 1)
#print(nums[i], nums[j])
print(dp_arr)
return max(dp_arr)
https://www.youtube.com/watch?v=CE2b_-XfVDk
'알고리즘 문제풀기' 카테고리의 다른 글
969. Pancake Sorting (0) | 2019.12.11 |
---|---|
1202. Smallest String With Swaps (0) | 2019.12.06 |
1048. Longest String Chain (0) | 2019.12.05 |
1219. Path with Maximum Gold (0) | 2019.12.04 |
988. Smallest String Starting From Leaf (0) | 2019.11.28 |