-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLeetCode674.java
More file actions
56 lines (52 loc) · 1.23 KB
/
LeetCode674.java
File metadata and controls
56 lines (52 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package problems;
import java.util.ArrayList;
import java.util.List;
/**
* 最长连续子序列
*/
public class LeetCode674 {
public int findLengthOfLCIS(int[] nums) {
int ans = 0;
int n = nums.length;
int start = 0;
for (int i = 0; i < n; i++) {
if (i > 0 && nums[i] <= nums[i - 1]) {
start = i;
}
ans = Math.max(ans, i - start + 1);
}
return ans;
}
}
class LeetCode674_1{
public int findLengthOfLCIS(int[] nums) {
int n = nums.length;
int ans = 0;
int start = 0;
for (int i = 0; i < n; i++) {
if(i > 0 && nums[i] <= nums[i - 1]) {
start = i;
}
ans = Math.max(ans, i - start + 1);
}
return ans;
}
}
class LeetCode674_2 {
public int findLengthOfLCIS(int[] nums) {
if(nums.length <= 1) {
return nums.length;
}
int ans = 1;
int count = 1;
for (int i = 1; i < nums.length; i++) {
if(nums[i] > nums[i - 1]) {
count ++;
} else {
count = 1;
}
ans = Math.max(ans, count);
}
return ans;
}
}