Guest User

Untitled

a guest
Jun 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. class Solution {
  2. public int findLength(int[] A, int[] B) {
  3. int[][] dp = new int[A.length+1][B.length+1];
  4. int ans = Integer.MIN_VALUE;
  5.  
  6. for(int i = 1; i <= A.length; i++) {
  7. for(int j = 1; j <= B.length; j++) {
  8. dp[i][j] = (A[i-1] == B[j-1]) ? dp[i-1][j-1] + 1 : 0;
  9. ans = Math.max(ans, dp[i][j]);
  10. }
  11. }
  12.  
  13. return ans;
  14. }
  15. }
Add Comment
Please, Sign In to add comment