<awangdev>Longest Common Subsequence_3.java
public int longestCommonSubsequence(String A, String B) {
        if (A == null || B == null || A.length() == 0 || B.length() == 0) {
            return 0;
        }
        int m = A.length();
        int n = B.length();
        int[][] dp = new int[m + 1][n + 1];
        int[][] pi = new int[m + 1][n + 1]; 
        
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= n; j++) {
                if(i == 0 || j == 0) {
                    dp[i][j] = 0;
                    continue;
                }
                dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
                pi[i][j] = dp[i - 1][j] > dp[i][j - 1] ? 1 : 2;

                if (A.charAt(i - 1) == B.charAt(j - 1)) {
                    dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - 1] + 1);
                    if (dp[i][j] == dp[i - 1][j - 1] + 1) {
                        pi[i][j] = 3;
                    }
                }
            }
        }

        char[] res = new char[dp[m][n]];
        int i = m;
        int j = n;
        int w = dp[m][n] - 1;
        while (i > 0 && j > 0) {
            if (pi[i][j] == 1) {
                i--;
            } else if (pi[i][j] == 2) {
                j--;
            } else {
                res[w] = A.charAt(i - 1);
                i--;
                j--;
                w--;
            }
        }

        for (int k = 0; k < dp[m][n]; k++) {
            System.out.print(res[k]);
        }
        System.out.println();
        
        return dp[m][n];
    }
public int sample_funcname ( String var_1 , String var_2 ) {
  if ( var_1 == null || var_2 == null || var_1 . length ( ) == 0 || var_2 . length ( ) == 0 ) {
    return 0 ;
  }
  int var_6 = var_1 . length ( ) ;
  int var_7 = var_2 . length ( ) ;
  int [ ] [ ] var_9 = new int [ var_6 + 1 ] [ var_7 + 1 ] ;
  int [ ] [ ] var_10 = new int [ var_6 + 1 ] [ var_7 + 1 ] ;
  for ( int var_11 = 1 ;
  var_11 <= var_6 ;
  var_11 ++ ) {
    for ( int var_12 = 1 ;
    var_12 <= var_7 ;
    var_12 ++ ) {
      if ( var_11 == 0 || var_12 == 0 ) {
        var_9 [ var_11 ] [ var_12 ] = 0 ;
        continue ;
      }
      var_9 [ var_11 ] [ var_12 ] = Math . max ( var_9 [ var_11 - 1 ] [ var_12 ] , var_9 [ var_11 ] [ var_12 - 1 ] ) ;
      var_10 [ var_11 ] [ var_12 ] = var_9 [ var_11 - 1 ] [ var_12 ] > var_9 [ var_11 ] [ var_12 - 1 ] ? 1 : 2 ;
      if ( var_1 . charAt ( var_11 - 1 ) == var_2 . charAt ( var_12 - 1 ) ) {
        var_9 [ var_11 ] [ var_12 ] = Math . max ( var_9 [ var_11 ] [ var_12 ] , var_9 [ var_11 - 1 ] [ var_12 - 1 ] + 1 ) ;
        if ( var_9 [ var_11 ] [ var_12 ] == var_9 [ var_11 - 1 ] [ var_12 - 1 ] + 1 ) {
          var_10 [ var_11 ] [ var_12 ] = 3 ;
        }
      }
    }
  }
  char [ ] var_18 = new char [ var_9 [ var_6 ] [ var_7 ] ] ;
  int var_11 = var_6 ;
  int var_12 = var_7 ;
  int var_19 = var_9 [ var_6 ] [ var_7 ] - 1 ;
  while ( var_11 > 0 && var_12 > 0 ) {
    if ( var_10 [ var_11 ] [ var_12 ] == 1 ) {
      var_11 -- ;
    }
    else if ( var_10 [ var_11 ] [ var_12 ] == 2 ) {
      var_12 -- ;
    }
    else {
      var_18 [ var_19 ] = var_1 . charAt ( var_11 - 1 ) ;
      var_11 -- ;
      var_12 -- ;
      var_19 -- ;
    }
  }
  for ( int var_20 = 0 ;
  var_20 < var_9 [ var_6 ] [ var_7 ] ;
  var_20 ++ ) {
    System . out . print ( var_18 [ var_20 ] ) ;
  }
  System . out . println ( ) ;
  return var_9 [ var_6 ] [ var_7 ] ;
}
