有两个未知的字符串A和B,写一个方法得出A和B的最大匹配子串。 

解决方案 »

  1.   

        public static String matcher(String s1, String s2) {       // the mini length String       String shortString = (s1.length()  < s2.length()) ? s1 : s2;       // the max length String       String longString = (s1.length()  < s2.length()) ? s2 : s1;        for (int i = shortString.length(); i > 0; i--) {           for (int j = 0; j  <= shortString.length() - i; j++) {              String subs = shortString.substring(j, j + i);              if (longString.indexOf(subs) > -1) {                  return subs;              }           }       }        return "";