public int longestCommonSubsequence(String A, String B) {
        // write your code here
        if (B.length() == 0)
            return 0;
        int[][] dp = new int[B.length() + 1][A.length() + 1];
        for (int i = 1; i <= B.length(); ++i) {
            for (int j = 1; j <= A.length(); ++j) {
                if (A.charAt(j - 1) != B.charAt(i - 1)) {
                    dp[i][j] = Math.max(dp[i][j - 1], dp[i - 1][j]);
                } else {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                }
            }
        }
        return dp[B.length()][A.length()];
    }