Q:

Given two strings, write a method that finds the longest common sub sequence

belongs to collection: java exercises (hard level )

0

Given two strings, write a method that finds the longest common sub sequence.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

public String findLongestCommonSequence(String s1, String s2) {
String result = "";
for (int length = s1.length(); length > 0; length--) {
    int startIndex = 0;
    while (startIndex + length <= s1.length()) {
        String current = s1.substring(startIndex, startIndex + length);
        if (s2.contains(current)) {
            result = current;
            break;
        }
        startIndex++;
    }
    if (result.length() != 0) {
        break;
    }
}
return result;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a method that calculates the largest prime f... >>
<< Write a method that returns the longest palindrome...