Skip to content

Commit

Permalink
Time: 36 ms (21.53%), Space: 13.1 MB (37.48%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Dipendra-Raghav committed May 11, 2023
1 parent e274b90 commit d4d3a0b
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions 1035-uncrossed-lines/1035-uncrossed-lines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@ class Solution {
{
if(i>=nums1.size() || j>=nums2.size())return 0;
if(dp[i][j]!=-1)return dp[i][j];
if(nums1[i]==nums2[j])
if(nums1[i]==nums2[j] && j>prev)
{
int b=solve(nums1,nums2,i,j+1,prev,dp);
int a=0;
if(j>prev)
{
prev=j;
a=1+solve(nums1,nums2,i+1,j+1,prev,dp);
}
return dp[i][j]=max(a,b);
prev=j;
return dp[i][j] =1+solve(nums1,nums2,i+1,j+1,prev,dp);
}
else
{
Expand Down

0 comments on commit d4d3a0b

Please sign in to comment.