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 e92686e commit 4f04c9cCopy full SHA for 4f04c9c
longest-common-subsequence/dev-jonghoonpark.md
@@ -0,0 +1,26 @@
1
+- 문제: https://leetcode.com/problems/longest-common-subsequence/
2
+- 풀이: https://algorithm.jonghoonpark.com/2024/07/17/leetcode-1143
3
+
4
+```java
5
+class Solution {
6
+ public int longestCommonSubsequence(String text1, String text2) {
7
+ int[][] dp = new int[text1.length() + 1][text2.length() + 1];
8
9
+ for (int i = 1; i < dp.length; i++) {
10
+ for (int j = 1; j < dp[0].length; j++) {
11
+ if (text1.charAt(i - 1) == text2.charAt(j - 1)) {
12
+ dp[i][j] = dp[i - 1][j - 1] + 1;
13
+ } else {
14
+ dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
15
+ }
16
17
18
19
+ return dp[text1.length()][text2.length()];
20
21
+}
22
+```
23
24
+### TC, SC
25
26
+시간 복잡도는 `O(m * n)` 공간 복잡도는 `O(m * n)` 이다.
0 commit comments