Iam_Sandeep

Untitled

Nov 25th, 2025
755
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. class LCSFinder {
  2.  
  3.     public int longestCommonSubsequence(String x, String y) {
  4.         int n = x.length();
  5.         int m = y.length();
  6.  
  7.         int[][] dp = new int[n + 1][m + 1];
  8.  
  9.         for (int i = 1; i <= n; i++) {
  10.             for (int j = 1; j <= m; j++) {
  11.                
  12.                 if (Character.toLowerCase(x.charAt(i - 1)) == Character.toLowerCase(y.charAt(j - 1))) {
  13.                     dp[i][j] = dp[i - 1][j - 1] + 1;
  14.                 } else {
  15.                     dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
  16.                 }
  17.             }
  18.         }
  19.  
  20.         return dp[n][m];
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment