1 The topic is to give two strings, and then to find the maximum length of the longest common substring of the two strings, assuming my f () method is to find the largest common substring of two strings, compare them from the beginning, and if they are equal,
Continue to call this method, so that the length of the recursion +1, if not equal, as long as the comparison S1 truncated one and S2 comparison, and S2 truncation and S1 comparison, the largest of two, if S1 or S2 has a length of 0, then the maximum public length is 0,return
2. code example:
Package Zzl;public class Longest common substring {public static void main (string[] args) {int a = f ("ABCD", "xacdb"); System.out.println (a);} private static int F (string s1, string s2) {if (S1.length () ==0 | | s2.length () ==0) {//s1 or S2 has one for 0return 0;} if (S1.charat (0) = = S2.charat (0)) {return F (s1.substring (1), s2.substring (1)) +1;//Take the next}else {return Math.max (f ( S1.substring (1), S2), F (s1,s2.substring (1))); Compare two Larger}}}
Java to find the length of the longest common substring