We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fe7397e commit 0584aabCopy full SHA for 0584aab
Dynamic Programming/300_Longest_Increasing_Subsequence.java
@@ -8,13 +8,13 @@ public int lengthOfLIS(int[] nums) {
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);
+ for (int currNum = 0; currNum < nums.length; currNum++) {
+ for (int prevNum = 0; prevNum < currNum; prevNum++) {
+ if (nums[currNum] > nums[prevNum]) {
+ dp[currNum] = Math.max(dp[currNum], dp[prevNum] + 1);
15
}
16
17
- max = Math.max(max, dp[i]);
+ max = Math.max(max, dp[currNum]);
18
19
20
return max;
0 commit comments