Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int findLength(int[] A, int[] B) {
- int[][] dp = new int[A.length+1][B.length+1];
- int ans = Integer.MIN_VALUE;
- for(int i = 1; i <= A.length; i++) {
- for(int j = 1; j <= B.length; j++) {
- dp[i][j] = (A[i-1] == B[j-1]) ? dp[i-1][j-1] + 1 : 0;
- ans = Math.max(ans, dp[i][j]);
- }
- }
- return ans;
- }
- }
Add Comment
Please, Sign In to add comment