Skip to content

Commit

Permalink
2024-07-05
Browse files Browse the repository at this point in the history
  • Loading branch information
mjj111 committed Jul 5, 2024
1 parent 2eefd97 commit ff7cf7b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions mjj111/LongestIncreasingSubsequence.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class LongestIncreasingSubsequence {
public int lengthOfLIS(int[] nums) {
int[] memo = new int[nums.length];
Arrays.fill(memo, 1);

for(int i = 0; i < nums.length; i++) {
int now = nums[i];
for(int j = i - 1; j >= 0; j--) {
int opp = nums[j];

if(opp < now) {
memo[i] = Math.max(memo[i], memo[j] + 1);
}
}
}
return Arrays.stream(memo).max().getAsInt();
}
}

0 comments on commit ff7cf7b

Please sign in to comment.