[Coding Made Simple] Longest Common Subsequence
Given two strings, find the longest common subsequence ( LCS ). Your code should return the length of LCS . Clarification What's the definition of Longest Common Subsequence? https://en.wikipedia.org/wiki/Longest_common_subsequence_problem http://baike.baidu.com/view/2020307.htm Example For "ABCD" and "EDCA" , the LCS is "A" (or "D" , "C" ), return 1 . For "ABCD" and "EACB" , the LCS is "AC" , return 2 . Solution 1. Recursion If we start to compare two characters from the end of both strings, we'll have the following possible cases. 1. A.charAt(n1 - 1) == B.charAt(n2 - 1), then the lcs is 1 +