Java LCS lcs(String arg0, String arg1)

Here you can find the source of lcs(String arg0, String arg1)

Description

lcs

License

Open Source License

Declaration


public static long lcs(String arg0, String arg1) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {

    public static long lcs(String arg0, String arg1) {
        if (arg0 == null || arg1 == null) {
            return 0;
        }//from  w  ww .  j a v  a2  s . com
        return lcs(arg0, arg1, 0, 0);
    }

    private static long lcs(String arg0, String arg1, int i, int j) {
        if (arg0.length() == i || arg1.length() == j) {
            return 0;
        }

        if (arg0.charAt(i) == arg1.charAt(j)) {
            return 1 + lcs(arg0, arg1, ++i, ++j);
        } else {
            return Math.max(lcs(arg0, arg1, ++i, j), lcs(arg0, arg1, i, ++j));
        }
    }
}

Related

  1. lcs(char[] inputString1, char[] inputString2, int length1, int length2)
  2. LCS(String a, String b)
  3. lcs(String a, String b)
  4. LCS(String A, String B)
  5. lcs(String a, String b)
  6. LCS(String input1, String input2)
  7. lcs(String s1, int s1min, int s1max, String s2, int s2min, int s2max)
  8. lcs(String s1, String s2)
  9. lcs(String str1, String str2)