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 75e9875 commit 7c6c91cCopy full SHA for 7c6c91c
longest-common-subsequence/jinvicky.java
@@ -0,0 +1,18 @@
1
+class Solution {
2
+ public int longestCommonSubsequence(String text1, String text2) {
3
+ int m = text1.length();
4
+ int n = text2.length();
5
+ int[][] dp = new int[m + 1][n + 1];
6
+
7
+ for (int i = 1; i <= m; i++) {
8
+ for (int j = 1; j <= n; j++) {
9
+ if (text1.charAt(i - 1) == text2.charAt(j - 1)) {
10
+ dp[i][j] = dp[i - 1][j - 1] + 1; // 문자가 같으면 대각선 값 + 1
11
+ } else {
12
+ dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]); // 위 or 왼쪽 중 큰 값
13
+ }
14
15
16
+ return dp[m][n];
17
18
+}
0 commit comments