Skip to content

Commit 0584aab

Browse files
Sean PrashadSean Prashad
authored andcommitted
Update 300_Longest_Increasing_Subsequence.java
1 parent fe7397e commit 0584aab

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Dynamic Programming/300_Longest_Increasing_Subsequence.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ public int lengthOfLIS(int[] nums) {
88
Arrays.fill(dp, 1);
99
int max = 1;
1010

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);
11+
for (int currNum = 0; currNum < nums.length; currNum++) {
12+
for (int prevNum = 0; prevNum < currNum; prevNum++) {
13+
if (nums[currNum] > nums[prevNum]) {
14+
dp[currNum] = Math.max(dp[currNum], dp[prevNum] + 1);
1515
}
1616
}
17-
max = Math.max(max, dp[i]);
17+
max = Math.max(max, dp[currNum]);
1818
}
1919

2020
return max;

0 commit comments

Comments
 (0)