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 e3571de commit d31ada6Copy full SHA for d31ada6
1 file changed
โlongest-increasing-subsequence/hyeri0903.pyโ
@@ -0,0 +1,26 @@
1
+class Solution:
2
+ def lengthOfLIS(self, nums: List[int]) -> int:
3
+ '''
4
+ ๋ชจ๋ฅด๊ฒ ์ด์ ํ์ด๋ดค์ต๋๋ค ใ ใ
5
+ 1.problem: ์ฆ๊ฐํ๋ ๊ฐ์ฅ ๊ธด subsequence length return (์ต์ฅ ์ฆ๊ฐ ๋ถ๋ถ ์์ด)
6
+ 2.์กฐ๊ฑด
7
+ - nums array ๊ธธ์ด ์ต์ 1 , ์ต๋ 2500
8
+ - ์์ ๊ฐ ์์ ๊ฐ๋ฅ
9
+ 3.ํ์ด
10
+ - dp : time complexity O(n^2)
11
+ dp[i] = i๋ฒ์งธ ์์๋ฅผ ๋ง์ง๋ง์ผ๋กํ๋ LIS
12
+ dp[i] max(dp[i], dp[j]+1) ๋ ๋ณด๋ค ์์ ์ ๋ค ์ค ๊ฐ์ฅ ๊ธด LIS + 1
13
14
+
15
+ n = len(nums)
16
+ dp = [1] * (n)
17
18
+ for i in range(n):
19
+ for j in range(i):
20
+ #์ ์ซ์ nums[j]๊ฐ ์ง๊ธ nums[i]๋ณด๋ค ๋ ์์ ๊ฒฝ์ฐ dp[i] update
21
+ if nums[j] < nums[i]:
22
+ dp[i] = max(dp[i], dp[j] + 1)
23
+ return max(dp)
24
25
26
0 commit comments