Skip to content

Commit 5327e8c

Browse files
committed
update: 添加问题“3350.检测相邻递增子数组II”的代码和题解 (#1174)
3350: AC.cpp (#1173) WA.cpp+py+go+java+rust AC.cpp - AC,5.12%,21.99% WA.cpp - 写法2 AC.cpp - 写法2,AC,98.49%,48.80% AC.py - AC,32.38%,85.24% AC.go - AC,91.89%,54.05% AC.java - AC,36.99%,75.72% AC.rust - AC,100.00%,20.00% Signed-off-by: LetMeFly666 <[email protected]>
1 parent 40cee1b commit 5327e8c

19 files changed

+443
-88
lines changed

.commitmsg

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
word: en+jp (#1169)
1+
3350: AC.cpp (#1173)
22

3-
en: 2025.10.12+2025.10.14(10.13背了但是没遇见生词)
4-
5-
3349: AC.cpp+py+go+java+rust
6-
cpp - AC,85.94%,46.88%
7-
WA.py
8-
py - AC,80.43%,19.57%
9-
go - AC,12.50%,87.50%
10-
CE.java
11-
java - AC,100.00%,25.58%
12-
rust - AC,-%,100.00%
3+
WA.cpp+py+go+java+rust
4+
AC.cpp - AC,5.12%,21.99%
5+
WA.cpp - 写法2
6+
AC.cpp - 写法2,AC,98.49%,48.80%
7+
AC.py - AC,32.38%,85.24%
8+
AC.go - AC,91.89%,54.05%
9+
AC.java - AC,36.99%,75.72%
10+
AC.rust - AC,100.00%,20.00%

Codes/3349-adjacent-increasing-subarrays-detection-i.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
* @Author: LetMeFly
33
* @Date: 2025-10-14 20:14:45
44
* @LastEditors: LetMeFly.xyz
5-
* @LastEditTime: 2025-10-14 20:30:13
5+
* @LastEditTime: 2025-10-14 20:41:48
66
*/
7-
// THIS IS NOT RIGHT
7+
// THIS IS RIGHT
88
class Solution {
99
private boolean isOk(List<Integer> nums, int i, int k) {
1010
while (--k > 0) {
11-
if (nums[i] >= nums[++i]) {
11+
if (nums.get(i) >= nums.get(++i)) {
1212
return false;
1313
}
1414
}
1515
return true;
1616
}
1717

1818
public boolean hasIncreasingSubarrays(List<Integer> nums, int k) {
19-
for (int i = 0; i + 2 * k <= nums.length(); i++) {
19+
for (int i = 0; i + 2 * k <= nums.size(); i++) { // List没有length方法
2020
if (isOk(nums, i, k) && isOk(nums, i + k, k)) {
2121
return true;
2222
}

Codes/3349-adjacent-increasing-subarrays-detection-i.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
Author: LetMeFly
33
Date: 2025-10-14 20:14:45
44
LastEditors: LetMeFly.xyz
5-
LastEditTime: 2025-10-14 20:21:32
5+
LastEditTime: 2025-10-14 20:24:03
66
'''
77
from typing import List
88

99
# THIS IS NOT RIGHT
1010
class Solution:
1111
def hasIncreasingSubarrays(self, nums: List[int], k: int) -> bool:
1212
for i in range(len(nums) - 2 * k + 1):
13-
if all(nums[j + 1] > nums[j] for j in range(i, i + k)) and all(nums[j + 1] > nums[j] for j in range(i + k, i + k * 2)):
13+
if all(nums[j + 1] > nums[j] for j in range(i, i + k - 1)) and all(nums[j + 1] > nums[j] for j in range(i + k, i + k * 2 - 1)):
1414
return True
1515
return False

Codes/3349-adjacent-increasing-subarrays-detection-i_right.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

Codes/3349-adjacent-increasing-subarrays-detection-i_right.py

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-10-15 22:07:17
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-10-15 22:12:42
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
// THIS IS NOT RIGHT
12+
class Solution {
13+
public:
14+
int maxIncreasingSubarrays(vector<int>& nums) {
15+
int ans = 1;
16+
int lastVal = 1000000001, lastCnt = 0, nowCnt = 0;
17+
for (int t : nums) {
18+
if (t <= lastVal) {
19+
ans = max(ans, min(lastCnt, nowCnt));
20+
ans = max(ans, nowCnt / 2);
21+
lastCnt = nowCnt, nowCnt = 0;
22+
} else {
23+
nowCnt++;
24+
}
25+
lastVal = t;
26+
}
27+
return ans;
28+
}
29+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-10-15 22:07:17
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-10-15 22:25:04
6+
*/
7+
package main
8+
9+
// 我发现nowCnt特别容易打成nowCNt
10+
func maxIncreasingSubarrays(nums []int) int {
11+
ans, lastCnt, nowCnt := 0, 0, 0
12+
for i, t := range nums {
13+
nowCnt++
14+
if i == len(nums) - 1 || t >= nums[i + 1] {
15+
ans = max(ans, max(min(lastCnt, nowCnt), nowCnt / 2))
16+
lastCnt, nowCnt = nowCnt, 0
17+
}
18+
}
19+
return ans
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-10-15 22:07:17
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-10-15 22:28:53
6+
*/
7+
class Solution {
8+
public int maxIncreasingSubarrays(List<Integer> nums) {
9+
int ans = 0;
10+
for (int i = 0, lastCnt = 0, nowCnt = 0; i < nums.size(); i++) {
11+
nowCnt++;
12+
if (i == nums.size() - 1 || nums.get(i) >= nums.get(i + 1)) { // 昨天踩过的bug今天不会再踩一次
13+
ans = Math.max(ans, Math.max(Math.min(lastCnt, nowCnt), nowCnt / 2));
14+
lastCnt = nowCnt;
15+
nowCnt = 0;
16+
}
17+
}
18+
return ans;
19+
}
20+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-10-15 22:07:17
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-10-15 22:23:10
6+
'''
7+
from typing import List
8+
9+
class Solution:
10+
def maxIncreasingSubarrays(self, nums: List[int]) -> int:
11+
ans = lastCnt = nowCnt = 0
12+
for i in range(len(nums)):
13+
nowCnt += 1
14+
if i == len(nums) - 1 or nums[i] >= nums[i + 1]:
15+
ans = max(ans, min(lastCnt, nowCnt), nowCnt // 2)
16+
lastCnt = nowCnt
17+
nowCnt = 0
18+
return ans
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-10-15 22:07:17
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-10-15 22:32:24
6+
*/
7+
impl Solution {
8+
pub fn max_increasing_subarrays(nums: Vec<i32>) -> i32 {
9+
let mut ans: i32 = 0;
10+
let mut last_cnt: i32 = 0;
11+
let mut now_cnt: i32 = 0;
12+
for i in 0..nums.len() {
13+
now_cnt += 1;
14+
if i == nums.len() - 1 || nums[i] >= nums[i + 1] {
15+
ans = ans.max(last_cnt.min(now_cnt)).max(now_cnt / 2);
16+
// (last_cnt, now_cnt) = (now_cnt, 0);
17+
last_cnt = now_cnt;
18+
now_cnt = 0;
19+
}
20+
}
21+
ans
22+
}
23+
}

0 commit comments

Comments
 (0)