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 ce8483f commit 35b80bdCopy full SHA for 35b80bd
Dynamic Programming/300. 最长递增子序列.md
@@ -66,4 +66,29 @@ class Solution {
66
return ans;
67
}
68
69
-```
+```
70
+
71
72
73
+或者初始化 `dp` 数组都为 `1`,然后仍然是遍历比较大小。
74
75
+```java
76
+class Solution {
77
+ public int lengthOfLIS(int[] nums) {
78
+ int n = nums.length;
79
+ int[] dp = new int[n];
80
+ for(int i = 0; i < n; i++) dp[i] = 1;
81
+ int res = 1;
82
+ for(int i = 1; i < nums.length; i++){
83
+ for(int j = 0; j < i; j++){
84
+ if(nums[i] > nums[j]){
85
+ dp[i] = Math.max(dp[i], dp[j] + 1);
86
+ }
87
88
+ res = Math.max(res, dp[i]);
89
90
+ return res;
91
92
+}
93
94
0 commit comments