@@ -14,7 +14,7 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3350.Ad
14
14
15
15
<!-- description:start -->
16
16
17
- <p >给你一个由 <code >n</code > 个整数组成的数组 <code >nums</code > ,请你找出 <code >k</code > 的 <strong >最大值</strong >,使得存在 <strong >两个</strong > <strong >相邻</strong > 且长度为 <code >k</code > 的 <strong >严格递增</strong > 子数组。具体来说,需要检查是否存在从下标 <code >a</code > 和 <code >b</code > (<code >a < ; b</code >) 开始的 <strong >两个</strong > 子数组,并满足下述全部条件:</p >
17
+ <p >给你一个由 <code >n</code > 个整数组成的数组 <code >nums</code > ,请你找出 <code >k</code > 的 <strong >最大值</strong >,使得存在 <strong >两个</strong > <strong >相邻</strong > 且长度为 <code >k</code > 的 <strong >严格递增</strong > < span data-keyword = " subarray-nonempty " > 子数组</ span > 。具体来说,需要检查是否存在从下标 <code >a</code > 和 <code >b</code > (<code >a < ; b</code >) 开始的 <strong >两个</strong > 子数组,并满足下述全部条件:</p >
18
18
19
19
<ul >
20
20
<li>这两个子数组 <code>nums[a..a + k - 1]</code> 和 <code>nums[b..b + k - 1]</code> 都是 <strong>严格递增</strong> 的。</li>
@@ -81,25 +81,89 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3350.Ad
81
81
#### Python3
82
82
83
83
``` python
84
-
84
+ class Solution :
85
+ def maxIncreasingSubarrays (self , nums : List[int ]) -> int :
86
+ ans = pre = cur = 0
87
+ for i, x in enumerate (nums):
88
+ cur += 1
89
+ if i == len (nums) - 1 or x >= nums[i + 1 ]:
90
+ ans = max (ans, cur // 2 , min (pre, cur))
91
+ pre, cur = cur, 0
92
+ return ans
85
93
```
86
94
87
95
#### Java
88
96
89
97
``` java
90
-
98
+ class Solution {
99
+ public int maxIncreasingSubarrays (List<Integer > nums ) {
100
+ int ans = 0 , pre = 0 , cur = 0 ;
101
+ int n = nums. size();
102
+ for (int i = 0 ; i < n; ++ i) {
103
+ ++ cur;
104
+ if (i == n - 1 || nums. get(i) >= nums. get(i + 1 )) {
105
+ ans = Math . max(ans, Math . max(cur / 2 , Math . min(pre, cur)));
106
+ pre = cur;
107
+ cur = 0 ;
108
+ }
109
+ }
110
+ return ans;
111
+ }
112
+ }
91
113
```
92
114
93
115
#### C++
94
116
95
117
``` cpp
96
-
118
+ class Solution {
119
+ public:
120
+ int maxIncreasingSubarrays(vector<int >& nums) {
121
+ int ans = 0, pre = 0, cur = 0;
122
+ int n = nums.size();
123
+ for (int i = 0; i < n; ++i) {
124
+ ++cur;
125
+ if (i == n - 1 || nums[ i] >= nums[ i + 1] ) {
126
+ ans = max({ans, cur / 2, min(pre, cur)});
127
+ pre = cur;
128
+ cur = 0;
129
+ }
130
+ }
131
+ return ans;
132
+ }
133
+ };
97
134
```
98
135
99
136
#### Go
100
137
101
138
```go
139
+ func maxIncreasingSubarrays(nums []int) (ans int) {
140
+ pre, cur := 0, 0
141
+ for i, x := range nums {
142
+ cur++
143
+ if i == len(nums)-1 || x >= nums[i+1] {
144
+ ans = max(ans, max(cur/2, min(pre, cur)))
145
+ pre, cur = cur, 0
146
+ }
147
+ }
148
+ return
149
+ }
150
+ ```
102
151
152
+ #### TypeScript
153
+
154
+ ``` ts
155
+ function maxIncreasingSubarrays(nums : number []): number {
156
+ let [ans, pre, cur] = [0 , 0 , 0 ];
157
+ const n = nums .length ;
158
+ for (let i = 0 ; i < n ; ++ i ) {
159
+ ++ cur ;
160
+ if (i === n - 1 || nums [i ] >= nums [i + 1 ]) {
161
+ ans = Math .max (ans , (cur / 2 ) | 0 , Math .min (pre , cur ));
162
+ [pre , cur ] = [cur , 0 ];
163
+ }
164
+ }
165
+ return ans ;
166
+ }
103
167
```
104
168
105
169
<!-- tabs: end -->
0 commit comments