@@ -36,19 +36,30 @@ increasing.
36
36
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
37
37
</ul >
38
38
39
-
40
39
## Solutions
41
40
42
41
<!-- tabs:start -->
43
42
44
43
### ** Python3**
45
44
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
+
46
59
``` python
47
60
class Solution :
48
61
def findLengthOfLCIS (self , nums : List[int ]) -> int :
49
62
n = len (nums)
50
- if n < 2 :
51
- return n
52
63
res = f = 1
53
64
for i in range (1 , n):
54
65
f = 1 + (f if nums[i - 1 ] < nums[i] else 0 )
@@ -61,10 +72,8 @@ class Solution:
61
72
``` java
62
73
class Solution {
63
74
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) {
68
77
f = 1 + (nums[i - 1 ] < nums[i] ? f : 0 );
69
78
res = Math . max(res, f);
70
79
}
@@ -73,6 +82,64 @@ class Solution {
73
82
}
74
83
```
75
84
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
+
76
143
### ** ...**
77
144
78
145
```
0 commit comments