Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0280ee0

Browse files
committed
feat: add solutions to lc problem: No.0674.Longest Continuous Increasing Subsequence
1 parent 3c28def commit 0280ee0

File tree

8 files changed

+183
-22
lines changed

8 files changed

+183
-22
lines changed

‎solution/0600-0699/0673.Number of Longest Increasing Subsequence/README.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
<p><strong>注意:</strong>&nbsp;给定的数组长度不超过 2000 并且结果一定是32位有符号整数。</p>
2828

29-
3029
## 解法
3130

3231
<!-- 这里可写通用的实现逻辑 -->

‎solution/0600-0699/0673.Number of Longest Increasing Subsequence/README_EN.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
<li><code>-10<sup>6</sup> &lt;= nums[i] &lt;= 10<sup>6</sup></code></li>
3535
</ul>
3636

37-
3837
## Solutions
3938

4039
similar problem: [LIS](/solution/0300-0399/0300.Longest%20Increasing%20Subsequence/README_EN.md)

‎solution/0600-0699/0674.Longest Continuous Increasing Subsequence/README.md‎

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
3939
</ul>
4040

41-
4241
## 解法
4342

4443
<!-- 这里可写通用的实现逻辑 -->
@@ -55,12 +54,24 @@
5554

5655
<!-- 这里可写当前语言的特殊实现逻辑 -->
5756

57+
```python
58+
class Solution:
59+
def findLengthOfLCIS(self, nums: List[int]) -> int:
60+
res, n = 1, len(nums)
61+
i = 0
62+
while i < n:
63+
j = i + 1
64+
while j < n and nums[j] > nums[j - 1]:
65+
j += 1
66+
res = max(res, j - i)
67+
i = j
68+
return res
69+
```
70+
5871
```python
5972
class Solution:
6073
def findLengthOfLCIS(self, nums: List[int]) -> int:
6174
n = len(nums)
62-
if n < 2:
63-
return n
6475
res = f = 1
6576
for i in range(1, n):
6677
f = 1 + (f if nums[i - 1] < nums[i] else 0)
@@ -75,10 +86,8 @@ class Solution:
7586
```java
7687
class Solution {
7788
public int findLengthOfLCIS(int[] nums) {
78-
int n;
79-
if ((n = nums.length) < 2) return n;
80-
int res = 1, f = 1;
81-
for (int i = 1; i < n; ++i) {
89+
int res = 1;
90+
for (int i = 1, f = 1; i < nums.length; ++i) {
8291
f = 1 + (nums[i - 1] < nums[i] ? f : 0);
8392
res = Math.max(res, f);
8493
}
@@ -87,6 +96,66 @@ class Solution {
8796
}
8897
```
8998

99+
双指针:
100+
101+
```java
102+
class Solution {
103+
public int findLengthOfLCIS(int[] nums) {
104+
int res = 1;
105+
for (int i = 0, n = nums.length; i < n;) {
106+
int j = i + 1;
107+
while (j < n && nums[j] > nums[j - 1]) {
108+
++j;
109+
}
110+
res = Math.max(res, j - i);
111+
i = j;
112+
}
113+
return res;
114+
}
115+
}
116+
```
117+
118+
### **C++**
119+
120+
```cpp
121+
class Solution {
122+
public:
123+
int findLengthOfLCIS(vector<int>& nums) {
124+
int res = 1;
125+
for (int i = 1, f = 1; i < nums.size(); ++i)
126+
{
127+
f = 1 + (nums[i - 1] < nums[i] ? f : 0);
128+
res = max(res, f);
129+
}
130+
return res;
131+
}
132+
};
133+
```
134+
135+
### **Go**
136+
137+
```go
138+
func findLengthOfLCIS(nums []int) int {
139+
res, f := 1, 1
140+
for i := 1; i < len(nums); i++ {
141+
if nums[i-1] < nums[i] {
142+
f += 1
143+
res = max(res, f)
144+
} else {
145+
f = 1
146+
}
147+
}
148+
return res
149+
}
150+
151+
func max(a, b int) int {
152+
if a > b {
153+
return a
154+
}
155+
return b
156+
}
157+
```
158+
90159
### **...**
91160

92161
```

‎solution/0600-0699/0674.Longest Continuous Increasing Subsequence/README_EN.md‎

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,30 @@ increasing.
3636
<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
3737
</ul>
3838

39-
4039
## Solutions
4140

4241
<!-- tabs:start -->
4342

4443
### **Python3**
4544

45+
```python
46+
class Solution:
47+
def findLengthOfLCIS(self, nums: List[int]) -> int:
48+
res, n = 1, len(nums)
49+
i = 0
50+
while i < n:
51+
j = i + 1
52+
while j < n and nums[j] > nums[j - 1]:
53+
j += 1
54+
res = max(res, j - i)
55+
i = j
56+
return res
57+
```
58+
4659
```python
4760
class Solution:
4861
def findLengthOfLCIS(self, nums: List[int]) -> int:
4962
n = len(nums)
50-
if n < 2:
51-
return n
5263
res = f = 1
5364
for i in range(1, n):
5465
f = 1 + (f if nums[i - 1] < nums[i] else 0)
@@ -61,10 +72,8 @@ class Solution:
6172
```java
6273
class Solution {
6374
public int findLengthOfLCIS(int[] nums) {
64-
int n;
65-
if ((n = nums.length) < 2) return n;
66-
int res = 1, f = 1;
67-
for (int i = 1; i < n; ++i) {
75+
int res = 1;
76+
for (int i = 1, f = 1; i < nums.length; ++i) {
6877
f = 1 + (nums[i - 1] < nums[i] ? f : 0);
6978
res = Math.max(res, f);
7079
}
@@ -73,6 +82,64 @@ class Solution {
7382
}
7483
```
7584

85+
```java
86+
class Solution {
87+
public int findLengthOfLCIS(int[] nums) {
88+
int res = 1;
89+
for (int i = 0, n = nums.length; i < n;) {
90+
int j = i + 1;
91+
while (j < n && nums[j] > nums[j - 1]) {
92+
++j;
93+
}
94+
res = Math.max(res, j - i);
95+
i = j;
96+
}
97+
return res;
98+
}
99+
}
100+
```
101+
102+
### **C++**
103+
104+
```cpp
105+
class Solution {
106+
public:
107+
int findLengthOfLCIS(vector<int>& nums) {
108+
int res = 1;
109+
for (int i = 1, f = 1; i < nums.size(); ++i)
110+
{
111+
f = 1 + (nums[i - 1] < nums[i] ? f : 0);
112+
res = max(res, f);
113+
}
114+
return res;
115+
}
116+
};
117+
```
118+
119+
### **Go**
120+
121+
```go
122+
func findLengthOfLCIS(nums []int) int {
123+
res, f := 1, 1
124+
for i := 1; i < len(nums); i++ {
125+
if nums[i-1] < nums[i] {
126+
f += 1
127+
res = max(res, f)
128+
} else {
129+
f = 1
130+
}
131+
}
132+
return res
133+
}
134+
135+
func max(a, b int) int {
136+
if a > b {
137+
return a
138+
}
139+
return b
140+
}
141+
```
142+
76143
### **...**
77144

78145
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
int findLengthOfLCIS(vector<int>& nums) {
4+
int res = 1;
5+
for (int i = 1, f = 1; i < nums.size(); ++i)
6+
{
7+
f = 1 + (nums[i - 1] < nums[i] ? f : 0);
8+
res = max(res, f);
9+
}
10+
return res;
11+
}
12+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
func findLengthOfLCIS(nums []int) int {
2+
res, f := 1, 1
3+
for i := 1; i < len(nums); i++ {
4+
if nums[i-1] < nums[i] {
5+
f += 1
6+
res = max(res, f)
7+
} else {
8+
f = 1
9+
}
10+
}
11+
return res
12+
}
13+
14+
func max(a, b int) int {
15+
if a > b {
16+
return a
17+
}
18+
return b
19+
}

‎solution/0600-0699/0674.Longest Continuous Increasing Subsequence/Solution.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
class Solution {
22
public int findLengthOfLCIS(int[] nums) {
3-
int n;
4-
if ((n = nums.length) < 2) return n;
5-
int res = 1, f = 1;
6-
for (int i = 1; i < n; ++i) {
3+
int res = 1;
4+
for (int i = 1, f = 1; i < nums.length; ++i) {
75
f = 1 + (nums[i - 1] < nums[i] ? f : 0);
86
res = Math.max(res, f);
97
}

‎solution/0600-0699/0674.Longest Continuous Increasing Subsequence/Solution.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
class Solution:
22
def findLengthOfLCIS(self, nums: List[int]) -> int:
33
n = len(nums)
4-
if n < 2:
5-
return n
64
res = f = 1
75
for i in range(1, n):
86
f = 1 + (f if nums[i - 1] < nums[i] else 0)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /