Skip to content

Commit 8c45f85

Browse files
LetMeFly666Copilot
andauthored
update: 添加问题“3201.找出有效子序列的最大长度I”的代码和题解(#1033)
* word: en * merge: original dev and master by hand(cherry-pick) (#1030) * merge: original dev and master by hand(cherry-pick) (#1030) * 3201: AC.cpp (#1030) AC,69.57%,84.78% * hello: #1032 (#1030) * 3201: WA.py (#1030) * 3201: AC.py (#1030) AC,100.00%,91.67% * 3201: AC.java+go (#1030) java - AC,80.00%,75.00% go - AC,72.73%,72.73% * update: 添加问题“3201.找出有效子序列的最大长度I”的代码和题解(#1033) Signed-off-by: LetMeFly666 <[email protected]> * typo: Update Solutions/LeetCode 3201.找出有效子序列的最大长度I.md Co-authored-by: Copilot <[email protected]> * x->n: Update Solutions/LeetCode 3201.找出有效子序列的最大长度I.md Co-authored-by: Copilot <[email protected]> * docs: 题目中没有说明n=len(nums) --------- Signed-off-by: LetMeFly666 <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 3607f07 commit 8c45f85

10 files changed

+385
-19
lines changed

.commitmsg

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

.gitlog

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
1-
PS F:\OtherApps\Program\Git\Store\Store20_LeetCode> git branch -d dev
2-
error: The branch 'dev' is not fully merged.
3-
If you are sure you want to delete it, run 'git branch -D dev'.
4-
PS F:\OtherApps\Program\Git\Store\Store20_LeetCode> git branch -D dev
5-
Deleted branch dev (was c2a5f471375).
6-
PS F:\OtherApps\Program\Git\Store\Store20_LeetCode>
1+
<!--
2+
* @Author: LetMeFly
3+
* @Date: 2025-07-16 12:54:42
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-07-16 13:00:06
6+
-->
7+
commit 711e3d3e6cb6b33b03bd7933d2efaa99d2f798fe (HEAD -> dev)
8+
Author: LetMeFly666 <[email protected]>
9+
Date: Mon Jul 14 19:00:34 2025 +0800
10+
11+
word: en
12+
13+
commit eed54c5ded68eee85ab6d272f3637863931e2949
14+
Author: LetMeFly666 <[email protected]>
15+
Date: Mon Jul 14 18:58:36 2025 +0800
16+
17+
fix: 昨晚消失的commit
18+
19+
Signed-off-by: LetMeFly666 <[email protected]>
20+
21+
22+
23+
git cherry-pick 711e3d3e6cb6b33b03bd7933d2efaa99d2f798fe
24+
自动合并 Solutions/Other-English-LearningNotes-SomeWords.md
25+
[dev 17b46a66d] word: en
26+
Date: Mon Jul 14 19:00:34 2025 +0800
27+
1 file changed, 4 insertions(+), 1 deletion(-)
28+
29+
➜ LeetCode git:(dev) git branch -d temp
30+
错误:分支 'temp' 没有完全合并
31+
提示: 如果您确认要删除它,执行 'git branch -D temp'
32+
提示: Disable this message with "git config set advice.forceDeleteBranch false"
33+
➜ LeetCode git:(dev) git branch -D temp
34+
已删除分支 temp(曾为 711e3d3e6)。
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-07-16 13:16:29
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-07-16 13:19:44
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
int maximumLength(vector<int>& nums) {
14+
int ans = 0;
15+
int odd = 0;
16+
bool last = nums[0] % 2 ? false : true;
17+
for (int t : nums) {
18+
if (t % 2) {
19+
odd++;
20+
if (!last) {
21+
last = true;
22+
ans++;
23+
}
24+
} else {
25+
if (last) {
26+
last = false;
27+
ans++;
28+
}
29+
}
30+
}
31+
return max(ans, max(odd, int(nums.size()) - odd));
32+
}
33+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-07-16 13:16:29
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-07-16 13:40:18
6+
*/
7+
package main
8+
9+
func maximumLength(nums []int) (ans int) {
10+
odd := 0
11+
last := nums[0] % 2 == 0
12+
for _, t := range nums {
13+
if t % 2 == 0 {
14+
if last {
15+
last = false
16+
ans++
17+
}
18+
} else {
19+
odd++
20+
if !last {
21+
last = true
22+
ans++
23+
}
24+
}
25+
}
26+
return max(ans, max(odd, len(nums) - odd))
27+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-07-16 13:16:29
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-07-16 13:41:23
6+
*/
7+
class Solution {
8+
public int maximumLength(int[] nums) {
9+
int ans = 0;
10+
int odd = 0;
11+
boolean last = nums[0] % 2 == 0;
12+
for (int t : nums) {
13+
if (t % 2 == 0) {
14+
if (last) {
15+
last = false;
16+
ans++;
17+
}
18+
} else {
19+
odd++;
20+
if (!last) {
21+
last = true;
22+
ans++;
23+
}
24+
}
25+
}
26+
return Math.max(ans, Math.max(odd, nums.length - odd));
27+
}
28+
}
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-07-16 13:16:29
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-07-16 13:36:53
6+
'''
7+
from typing import List
8+
9+
class Solution:
10+
def maximumLength(self, nums: List[int]) -> int:
11+
ans = odd = 0
12+
last = False if nums[0] % 2 else True
13+
for t in nums:
14+
if t % 2:
15+
odd += 1
16+
if not last:
17+
last = True
18+
ans += 1
19+
else:
20+
if last:
21+
last = False
22+
ans += 1
23+
return max(ans, odd, len(nums) - odd)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,7 @@
954954
|3192.使二进制数组全部等于1的最少操作次数II|中等|<a href="https://leetcode.cn/problems/minimum-operations-to-make-binary-array-elements-equal-to-one-ii/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/10/19/LeetCode%203192.%E4%BD%BF%E4%BA%8C%E8%BF%9B%E5%88%B6%E6%95%B0%E7%BB%84%E5%85%A8%E9%83%A8%E7%AD%89%E4%BA%8E1%E7%9A%84%E6%9C%80%E5%B0%91%E6%93%8D%E4%BD%9C%E6%AC%A1%E6%95%B0II/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/143066863" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/minimum-operations-to-make-binary-array-elements-equal-to-one-ii/solutions/2956341/letmefly-3192shi-er-jin-zhi-shu-zu-quan-ih15d/" target="_blank">LeetCode题解</a>|
955955
|3194.最小元素和最大元素的最小平均值|简单|<a href="https://leetcode.cn/problems/minimum-average-of-smallest-and-largest-elements/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/10/16/LeetCode%203194.%E6%9C%80%E5%B0%8F%E5%85%83%E7%B4%A0%E5%92%8C%E6%9C%80%E5%A4%A7%E5%85%83%E7%B4%A0%E7%9A%84%E6%9C%80%E5%B0%8F%E5%B9%B3%E5%9D%87%E5%80%BC/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/142994095" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/minimum-average-of-smallest-and-largest-elements/solutions/2953616/letmefly-3194zui-xiao-yuan-su-he-zui-da-6f4v5/" target="_blank">LeetCode题解</a>|
956956
|3200.三角形的最大高度|简单|<a href="https://leetcode.cn/problems/maximum-height-of-a-triangle/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/10/15/LeetCode%203200.%E4%B8%89%E8%A7%92%E5%BD%A2%E7%9A%84%E6%9C%80%E5%A4%A7%E9%AB%98%E5%BA%A6/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/142967272" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/maximum-height-of-a-triangle/solutions/2952209/letmefly-3200san-jiao-xing-de-zui-da-gao-m23t/" target="_blank">LeetCode题解</a>|
957+
|3201.找出有效子序列的最大长度I|中等|<a href="https://leetcode.cn/problems/find-the-maximum-length-of-valid-subsequence-i/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/07/16/LeetCode%203201.%E6%89%BE%E5%87%BA%E6%9C%89%E6%95%88%E5%AD%90%E5%BA%8F%E5%88%97%E7%9A%84%E6%9C%80%E5%A4%A7%E9%95%BF%E5%BA%A6I/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/149409629" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-the-maximum-length-of-valid-subsequence-i/solutions/3725834/letmefly-3201zhao-chu-you-xiao-zi-xu-lie-3quj/" target="_blank">LeetCode题解</a>|
957958
|3206.交替组I|简单|<a href="https://leetcode.cn/problems/alternating-groups-i/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/11/26/LeetCode%203206.%E4%BA%A4%E6%9B%BF%E7%BB%84I/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/144071026" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/alternating-groups-i/solutions/3001910/letmefly-3206jiao-ti-zu-ibian-li-by-tisf-euqx/" target="_blank">LeetCode题解</a>|
958959
|3208.交替组II|中等|<a href="https://leetcode.cn/problems/alternating-groups-ii/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/11/28/LeetCode%203208.%E4%BA%A4%E6%9B%BF%E7%BB%84II/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/144123453" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/alternating-groups-ii/solutions/3004235/letmefly-3208jiao-ti-zu-iihua-dong-chuan-5bcc/" target="_blank">LeetCode题解</a>|
959960
|3211.生成不含相邻零的二进制字符串|中等|<a href="https://leetcode.cn/problems/generate-binary-strings-without-adjacent-zeros/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/10/29/LeetCode%203211.%E7%94%9F%E6%88%90%E4%B8%8D%E5%90%AB%E7%9B%B8%E9%82%BB%E9%9B%B6%E7%9A%84%E4%BA%8C%E8%BF%9B%E5%88%B6%E5%AD%97%E7%AC%A6%E4%B8%B2/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/143352841" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/generate-binary-strings-without-adjacent-zeros/solutions/2970587/letmefly-3211sheng-cheng-bu-han-xiang-li-sdh3/" target="_blank">LeetCode题解</a>|

0 commit comments

Comments
 (0)