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 72ea223 commit 52cc3d5Copy full SHA for 52cc3d5
longest-common-subsequence/pmjuu.py
@@ -0,0 +1,20 @@
1
+'''
2
+시간 복잡도: O(m * n)
3
+공간 복잡도: O(n)
4
5
+
6
+class Solution:
7
+ def longestCommonSubsequence(self, text1: str, text2: str) -> int:
8
+ m, n = len(text1), len(text2)
9
+ prev = [0] * (n + 1)
10
11
+ for i in range(1, m + 1):
12
+ curr = [0] * (n + 1)
13
+ for j in range(1, n + 1):
14
+ if text1[i - 1] == text2[j - 1]:
15
+ curr[j] = prev[j - 1] + 1
16
+ else:
17
+ curr[j] = max(prev[j], curr[j - 1])
18
+ prev = curr # 현재 행을 이전 행으로 업데이트
19
20
+ return prev[n]
0 commit comments