Skip to content

Commit 10a452e

Browse files
authored
update: 添加问题“66.加一”的代码和题解 (#1296)
* word: en * 66: WA.cpp * 66: AC.cpp (#1295) - AC,100.00%,75.94% * 66: AC.pyx2+java+rust+go (#1295) py - AC,100.00%,84.44% py - oneline,int list, AC,100.00%,93.49% java - AC,100.00%,8.27% rust - AC,100.00%,26.56% go - AC,100.00%,79.71% * update: 添加问题“66.加一”的代码和题解 (#1296) Signed-off-by: LetMeFly666 <814114971@qq.com> * 1problem1day: todo * 1problem1day: only when `solving` label --------- Signed-off-by: LetMeFly666 <814114971@qq.com>
1 parent b24bdca commit 10a452e

13 files changed

+352
-2
lines changed

.github/workflows/1problem1day-autoGenIssueEveryday.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
-H 'Content-Type: application/json' \
2626
-d "{
2727
\"query\":\"query dailyQuestionRecords(\$year:Int!,\$month:Int!){dailyQuestionRecords(year:\$year,month:\$month){date question{questionFrontendId titleSlug translatedTitle}}}\",
28-
\"variables\":{\"year\":$year,\"month\":$month}
28+
\"variables\":{\"year\":\"$year\",\"month\":\"$month\"}
2929
}" \
3030
| jq -r --arg d "$date" '
3131
.data.dailyQuestionRecords[]

.github/workflows/1problem1day-label.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ jobs:
3535
echo "label(event) = ${{ github.event.label.name }}"
3636
echo "======================="
3737
38+
# 非solving标签改动时退出
39+
label_event="${{ github.event.label.name }}"
40+
if [[ "$label_event" != "solving" ]]; then
41+
echo "Label '$label_event' is not 'solving', skip workflow"
42+
echo "skip=true" >> $GITHUB_OUTPUT
43+
exit 0
44+
fi
45+
3846
issue_node_id="${{ github.event.issue.node_id }}"
3947
issue_state="${{ github.event.issue.state }}"
4048

Codes/0066-plus-one.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-01-01 15:40:30
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-01-01 15:44:13
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
vector<int> plusOne(vector<int>& digits) {
14+
int cnt = 1;
15+
for (int i = digits.size() - 1; i >= 0; i--) {
16+
digits[i] += cnt;
17+
cnt = digits[i] / 10;
18+
digits[i] %= 10;
19+
}
20+
if (cnt) {
21+
digits.insert(digits.begin(), cnt);
22+
}
23+
return digits;
24+
}
25+
};

Codes/0066-plus-one.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-01-01 15:40:30
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-01-01 16:09:18
6+
*/
7+
package main
8+
9+
func plusOne(digits []int) []int {
10+
cnt := 1
11+
for i := len(digits) - 1; i >= 0; i-- {
12+
digits[i] += cnt
13+
cnt = digits[i] / 10
14+
digits[i] %= 10
15+
}
16+
if cnt > 0 {
17+
return append([]int{cnt}, digits...)
18+
}
19+
return digits
20+
}

Codes/0066-plus-one.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-01-01 15:40:30
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-01-01 15:59:15
6+
*/
7+
class Solution {
8+
public int[] plusOne(int[] digits) {
9+
int cnt = 1;
10+
for (int i = digits.length - 1; i >= 0; i--) {
11+
digits[i] += cnt;
12+
cnt = digits[i] / 10;
13+
digits[i] %= 10;
14+
}
15+
if (cnt > 0) {
16+
int[] ans = new int[digits.length + 1];
17+
ans[0] = cnt;
18+
for (int i = 0; i < digits.length; i++) {
19+
ans[i + 1] = digits[i];
20+
}
21+
return ans;
22+
}
23+
return digits;
24+
}
25+
}

Codes/0066-plus-one.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2026-01-01 15:40:30
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2026-01-01 15:54:44
6+
'''
7+
from typing import List
8+
9+
class Solution:
10+
def plusOne(self, digits: List[int]) -> List[int]:
11+
cnt = 1
12+
for i in range(len(digits) - 1, -1, -1):
13+
digits[i] += cnt
14+
cnt = digits[i] // 10
15+
digits[i] %= 10
16+
if cnt:
17+
digits = [1] + digits
18+
return digits

Codes/0066-plus-one.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-01-01 15:40:30
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-01-01 16:06:45
6+
*/
7+
impl Solution {
8+
pub fn plus_one(mut digits: Vec<i32>) -> Vec<i32> {
9+
let mut cnt: i32 = 1;
10+
for i in (0..digits.len()).rev() {
11+
digits[i] += cnt;
12+
cnt = digits[i] / 10;
13+
digits[i] %= 10;
14+
}
15+
if cnt > 0 {
16+
digits.insert(0, cnt);
17+
}
18+
digits
19+
}
20+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2026-01-01 15:54:45
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2026-01-01 16:03:01
6+
'''
7+
from typing import List
8+
9+
class Solution:
10+
def plusOne(self, digits: List[int]) -> List[int]:
11+
return list(map(int, str(int(''.join(map(str, digits))) + 1)))
12+
13+
if __name__ == '__main__':
14+
sol = Solution()
15+
print(sol.plusOne([1,2,3]))

Codes/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
* @LastEditTime: 2025-11-01 22:18:35
66
*/
77
pub struct Solution;
8-
include!("3075-maximize-happiness-of-selected-children.rs"); // 这个fileName是会被脚本替换掉的
8+
include!("0066-plus-one.rs"); // 这个fileName是会被脚本替换掉的

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
|0059.螺旋矩阵II|中等|<a href="https://leetcode.cn/problems/spiral-matrix-ii/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/02/07/LeetCode%200059.%E8%9E%BA%E6%97%8B%E7%9F%A9%E9%98%B5II/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/145502589" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/spiral-matrix-ii/solutions/3066956/letmefly-59luo-xuan-ju-zhen-iiyou-zhi-da-vuyg/" target="_blank">LeetCode题解</a>|
184184
|0062.不同路径|中等|<a href="https://leetcode.cn/problems/unique-paths/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/11/26/LeetCode%200062.%E4%B8%8D%E5%90%8C%E8%B7%AF%E5%BE%84/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/128059055" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/unique-paths/solutions/1992721/letmefly-62bu-tong-lu-jing-liang-chong-f-e8tl/" target="_blank">LeetCode题解</a>|
185185
|0063.不同路径II|中等|<a href="https://leetcode.cn/problems/unique-paths-ii/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/02/08/LeetCode%200063.%E4%B8%8D%E5%90%8C%E8%B7%AF%E5%BE%84II/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/145509662" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/unique-paths-ii/solutions/3067362/letmefly-63bu-tong-lu-jing-iidong-tai-gu-je2m/" target="_blank">LeetCode题解</a>|
186+
|0066.加一|简单|<a href="https://leetcode.cn/problems/plus-one/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2026/01/01/LeetCode%200066.%E5%8A%A0%E4%B8%80/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/156488092" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/plus-one/solutions/3870599/letmefly-66jia-yi-mo-ni-fu-jian-dan-ti-b-02dl/" target="_blank">LeetCode题解</a>|
186187
|0067.二进制求和|简单|<a href="https://leetcode.cn/problems/add-binary/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/07/14/LeetCode%200067.%E4%BA%8C%E8%BF%9B%E5%88%B6%E6%B1%82%E5%92%8C/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/125793685" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/add-binary/solution/by-tisfy-o5z5/" target="_blank">LeetCode题解</a>|
187188
|0070.爬楼梯|简单|<a href="https://leetcode.cn/problems/climbing-stairs/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/12/10/LeetCode%200070.%E7%88%AC%E6%A5%BC%E6%A2%AF/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/134913892" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/climbing-stairs/solutions/2561558/letmefly-70pa-lou-ti-dong-tai-gui-hua-di-7d8m/" target="_blank">LeetCode题解</a>|
188189
|0080.删除有序数组中的重复项II|中等|<a href="https://leetcode.cn/problems/remove-duplicates-from-sorted-array-ii/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/02/09/LeetCode%200080.%E5%88%A0%E9%99%A4%E6%9C%89%E5%BA%8F%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E9%87%8D%E5%A4%8D%E9%A1%B9II/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/145528267" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/remove-duplicates-from-sorted-array-ii/solutions/3068455/letmefly-80shan-chu-you-xu-shu-zu-zhong-b1e2i/" target="_blank">LeetCode题解</a>|

0 commit comments

Comments
 (0)