Skip to content

Commit 162dd59

Browse files
committed
0674-longest-continuous-increasing-subsequence.md Perfected Java code, etc.
1 parent 3ff2582 commit 162dd59

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

problems/0674-longest-continuous-increasing-subsequence.md

+24-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 674. Longest Continuous Increasing Subsequence
2-
LeetCode problem: [674. Longest Continuous Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence/)
2+
LeetCode problem: [674. Longest Continuous Increasing Subsequence](https://leetcode.com/problems/longest-continuous-increasing-subsequence/)
33

44
## LeetCode problem description
55
Given an integer array `nums`, return the length of the **longest strictly increasing subsequence**.
@@ -26,7 +26,7 @@ Output: 1
2626
[Constraints]
2727
2828
1 <= nums.length <= 2500
29-
-104 <= nums[i] <= 10000
29+
-10000 <= nums[i] <= 10000
3030
----------------------------------------------------------------------------------------------
3131
```
3232

@@ -54,7 +54,27 @@ public class Solution {
5454
}
5555
}
5656

57-
return dp.Max(); // If you want to beat 90%, change this line by using a local variable to record the max value in iteration.
57+
return dp.Max(); // If you want to beat 90%, refer to Java code.
58+
}
59+
}
60+
```
61+
62+
## Java
63+
```java
64+
class Solution {
65+
public int findLengthOfLCIS(int[] nums) {
66+
var result = 1;
67+
var dp = new int[nums.length];
68+
Arrays.fill(dp, 1);
69+
70+
for (var i = 1; i < nums.length; i++) {
71+
if (nums[i] > nums[i - 1]) {
72+
dp[i] = dp[i - 1] + 1;
73+
result = Math.max(result, dp[i]);
74+
}
75+
}
76+
77+
return result;
5878
}
5979
}
6080
```
@@ -80,24 +100,6 @@ class Solution:
80100
// Welcome to create a PR to complete the code of this language, thanks!
81101
```
82102

83-
## Java
84-
```java
85-
class Solution {
86-
public int findLengthOfLCIS(int[] nums) {
87-
var dp = new int[nums.length];
88-
Arrays.fill(dp, 1);
89-
90-
for (var i = 1; i < nums.length; i++) {
91-
if (nums[i] > nums[i - 1]) {
92-
dp[i] = dp[i - 1] + 1;
93-
}
94-
}
95-
96-
return IntStream.of(dp).max().getAsInt(); // If you want to beat 90%, refer to C#'s code comment.
97-
}
98-
}
99-
```
100-
101103
## JavaScript
102104
```javascript
103105
var findLengthOfLCIS = function (nums) {
@@ -111,7 +113,7 @@ var findLengthOfLCIS = function (nums) {
111113
}
112114
})
113115

114-
return Math.max(...dp) // If you want to beat 90%, refer to C#'s code comment.
116+
return Math.max(...dp) // If you want to beat 90%, refer to Java code.
115117
};
116118
```
117119

0 commit comments

Comments
 (0)