Skip to content

Commit 3670680

Browse files
Sean PrashadSean Prashad
authored andcommitted
Add 300_Longest_Increasing_Subsequence.java
1 parent 3f583cc commit 3670680

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public int lengthOfLIS(int[] nums) {
3+
if (nums == null || nums.length == 0) {
4+
return 0;
5+
}
6+
7+
int[] dp = new int[nums.length];
8+
Arrays.fill(dp, 1);
9+
int max = 1;
10+
11+
for (int i = 0; i < nums.length; i++) {
12+
for (int j = 0; j < i; j++) {
13+
if (nums[i] > nums[j]) {
14+
dp[i] = Math.max(dp[i], dp[j] + 1);
15+
}
16+
}
17+
max = Math.max(max, dp[i]);
18+
}
19+
20+
return max;
21+
}
22+
}

0 commit comments

Comments
 (0)