mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 14:34:05 +08:00
Format code with prettier (#3375)
This commit is contained in:
@ -3,7 +3,6 @@ package com.thealgorithms.dynamicprogramming;
|
||||
class LongestCommonSubsequence {
|
||||
|
||||
public static String getLCS(String str1, String str2) {
|
||||
|
||||
// At least one string is null
|
||||
if (str1 == null || str2 == null) {
|
||||
return null;
|
||||
@ -31,15 +30,21 @@ class LongestCommonSubsequence {
|
||||
if (arr1[i - 1].equals(arr2[j - 1])) {
|
||||
lcsMatrix[i][j] = lcsMatrix[i - 1][j - 1] + 1;
|
||||
} else {
|
||||
lcsMatrix[i][j]
|
||||
= lcsMatrix[i - 1][j] > lcsMatrix[i][j - 1] ? lcsMatrix[i - 1][j] : lcsMatrix[i][j - 1];
|
||||
lcsMatrix[i][j] =
|
||||
lcsMatrix[i - 1][j] > lcsMatrix[i][j - 1]
|
||||
? lcsMatrix[i - 1][j]
|
||||
: lcsMatrix[i][j - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
return lcsString(str1, str2, lcsMatrix);
|
||||
}
|
||||
|
||||
public static String lcsString(String str1, String str2, int[][] lcsMatrix) {
|
||||
public static String lcsString(
|
||||
String str1,
|
||||
String str2,
|
||||
int[][] lcsMatrix
|
||||
) {
|
||||
StringBuilder lcs = new StringBuilder();
|
||||
int i = str1.length(), j = str2.length();
|
||||
while (i > 0 && j > 0) {
|
||||
|
Reference in New Issue
Block a user