Skip to content

Commit b25bf5f

Browse files
committed
feat: add the solution of Longest Continuous Increasing Subsequence(674) with Java.
1 parent 8a28586 commit b25bf5f

File tree

3 files changed

+69
-25
lines changed

3 files changed

+69
-25
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
| [665][665-question] | [Non-decreasing Array][665-tips] | [][665-java] | [][665-js] | |
7171
| [669][669-question] | [Trim a Binary Search Tree][669-tips] | [][669-java] | [][669-js] | |
7272
| [671][671-question] | [Second Minimum Node In a Binary Tree][671-tips] | [][671-java] | [][671-js] | |
73-
| [674][674-question] | [Longest Continuous Increasing Subsequence][674-tips] | | [][674-js] | |
73+
| [674][674-question] | [Longest Continuous Increasing Subsequence][674-tips] | [][674-java] | [][674-js] | |
7474
| [680][680-question] | [Valid Palindrome II][680-tips] | | [][680-js] | |
7575
| [682][682-question] | [Baseball Game][682-tips] | | [][682-js] | |
7676
| [686][686-question] | [Repeated String Match][686-tips] | | [][686-js] | |
@@ -463,6 +463,7 @@
463463
[665-java]: ./src/_665/Solution.java
464464
[669-java]: ./src/_669/Solution.java
465465
[671-java]: ./src/_671/Solution.java
466+
[674-java]: ./src/_674/Solution.java
466467
[728-java]: ./src/_728/Solution.java
467468
[771-java]: ./src/_771/Solution.java
468469
[804-java]: ./src/_804/Solution.java

src/_674/Solution.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package _674;
2+
3+
class Solution {
4+
public int findLengthOfLCIS(int[] nums) {
5+
if (nums.length == 0) {
6+
return 0;
7+
}
8+
int len = 1;
9+
int maxLen = 1;
10+
for (int i = 1; i < nums.length; i++) {
11+
if (nums[i] > nums[i-1]) {
12+
len++;
13+
if (len > maxLen) {
14+
maxLen = len;
15+
}
16+
} else {
17+
len = 1;
18+
}
19+
}
20+
return maxLen;
21+
}
22+
23+
public static void main(String[] args) {
24+
Solution solution = new Solution();
25+
System.out.println(solution.findLengthOfLCIS(new int[] {1, 3, 5, 4, 7}));
26+
System.out.println(solution.findLengthOfLCIS(new int[] {2, 2, 2, 2}));
27+
}
28+
}

tips/674/README.md

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,61 @@
1-
[xxxx][title]
1+
[Longest Continuous Increasing Subsequence][title]
22

33
## Description
4-
// 抄题目
5-
4+
Given an unsorted array of integers, find the length of longest `continuous` increasing subsequence (subarray).
65

76
**Example:**
87

98
```
10-
// 抄Example
9+
Input: [1,3,5,4,7]
10+
Output: 3
11+
Explanation: The longest continuous increasing subsequence is [1,3,5], its length is 3.
12+
Even though [1,3,5,7] is also an increasing subsequence, it's not a continuous one where 5 and 7 are separated by 4.
1113
```
1214

13-
**Note:**
14-
// Note
15+
**Example 2:**
1516

16-
**Tags:** // tags
17+
```
18+
Input: [2,2,2,2,2]
19+
Output: 1
20+
Explanation: The longest continuous increasing subsequence is [2], its length is 1.
21+
```
1722

23+
**Note:**
1824

19-
## 思路 1
20-
// 贴一些关键代码,说一些解题思路
21-
// (同一种语言可以写多种思路,与某种语言思路相同的另一种语言的思路无须赘述,但可以把代码贴在后面)
22-
```java
25+
Length of the array will not exceed 10,000.
2326

24-
```
25-
```javascript
27+
**Tags:** [Array](https://leetcode.com/tag/array/)
2628

27-
```
28-
29-
## 思路 2
30-
// 贴一些关键代码,说一些解题思路
31-
```java
29+
## 思路
3230

33-
```
31+
找出所给数组中的最长连续递增子数组的长度。
3432

35-
## 思路 3
36-
// 贴一些关键代码,说一些解题思路
37-
```kotlin
33+
**Java:**
3834

35+
```java
36+
public int findLengthOfLCIS(int[] nums) {
37+
if (nums.length == 0) {
38+
return 0;
39+
}
40+
int len = 1;
41+
int maxLen = 1;
42+
for (int i = 1; i < nums.length; i++) {
43+
if (nums[i] > nums[i-1]) {
44+
len++;
45+
if (len > maxLen) {
46+
maxLen = len;
47+
}
48+
} else {
49+
len = 1;
50+
}
51+
}
52+
return maxLen;
53+
}
3954
```
4055

4156
## 结语
42-
57+
4358
如果你同我们一样热爱数据结构、算法、LeetCode,可以关注我们 GitHub 上的 LeetCode 题解:[LeetCode-Solution][ls]
4459

45-
[title]: https://leetcode.com/problems/xxxx
60+
[title]: https://leetcode.com/problems/longest-continuous-increasing-subsequence/description/
4661
[ls]: https://github.com/SDE603/LeetCode-Solution

0 commit comments

Comments
 (0)