We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 684763d commit d4a1e12Copy full SHA for d4a1e12
longest-increasing-subsequence/yyyyyyyyyKim.py
@@ -0,0 +1,16 @@
1
+class Solution:
2
+ def lengthOfLIS(self, nums: List[int]) -> int:
3
+
4
+ # DP(각 인덱스를 끝으로 하는 LIS의 최대 길이 저장)
5
+ dp = [1]*len(nums) # 초기값은 1(자신 하나만 있을 경우)
6
7
+ for i in range(len(nums)):
8
+ for j in range(i):
9
+ # 현재값(nums[i])이 이전값(nums[j])보다 크면 dp[i]업데이트
10
+ if nums[i] > nums[j]:
11
+ dp[i] = max(dp[i],dp[j]+1)
12
13
+ # dp에 저장된 최대값 리턴
14
+ return max(dp)
15
16
+# 시간복잡도 O(n^2), 공간복잡도 O(n)
0 commit comments