Skip to content

Commit ec954cb

Browse files
authored
update: 添加问题“118.杨辉三角”的代码和题解(#1058)
* feat: test 后台子进程 - Mac上会后台继续运行 0118: - AC.cpp+py + Half.java (#1057) cpp - AC,100.00%,5.38% py - AC,100.00%,21.96% * 0118: - AC.java+go + CE.rust (#1057) java - AC,97.77%,33.33% (好冗长) go - AC,100.00%,49.58% * 0118: - AC.rust (#1057) rust - AC,100.00%,80.39% * update: 添加问题“118. 杨辉三角”的代码并更新其题解 (#1057) * docs: en+jp yesterday (#1057) * word: en words today (2025.08.03) (#1057) * update: 添加问题“118.杨辉三角”的代码(并更新其题解) (#1058) Signed-off-by: LetMeFly666 <[email protected]> --------- Signed-off-by: LetMeFly666 <[email protected]>
1 parent ec9494c commit ec954cb

13 files changed

+293
-27
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@
8989
"__hash_table": "cpp",
9090
"__split_buffer": "cpp",
9191
"__tree": "cpp",
92-
"queue": "cpp"
92+
"queue": "cpp",
93+
"span": "cpp",
94+
"__locale": "cpp",
95+
"ios": "cpp"
9396
},
9497
"editor.mouseWheelZoom": true,
9598
"workbench.tree.enableStickyScroll": true,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-08-01 23:51:32
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-08-01 23:55:15
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
vector<vector<int>> generate(int numRows) {
14+
vector<vector<int>> ans(numRows);
15+
ans[0].push_back(1);
16+
for (int i = 1; i < numRows; i++) {
17+
ans[i].push_back(1);
18+
for (int j = 1; j < i; j++) {
19+
ans[i].push_back(ans[i - 1][j - 1] + ans[i - 1][j]);
20+
}
21+
ans[i].push_back(1);
22+
}
23+
return ans;
24+
}
25+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-08-01 23:51:32
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-08-02 13:12:32
6+
*/
7+
package main
8+
9+
func generate(numRows int) [][]int {
10+
ans := make([][]int, numRows)
11+
ans[0] = []int{1}
12+
for i := 1; i < numRows; i++ {
13+
ans[i] = make([]int, i + 1)
14+
ans[i][0] = 1
15+
for j := 1; j < i; j++ {
16+
ans[i][j] = ans[i - 1][j - 1] + ans[i - 1][j]
17+
}
18+
ans[i][i] = 1
19+
}
20+
return ans
21+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-08-01 23:51:32
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-08-02 12:47:48
6+
*/
7+
import java.util.List;
8+
import java.util.ArrayList;
9+
10+
class Solution {
11+
public List<List<Integer>> generate(int numRows) {
12+
List<List<Integer>> ans = new ArrayList<>(numRows);
13+
ans.add(List.of(1));
14+
for (int i = 1; i < numRows; i++) {
15+
ans.add(new ArrayList<>(i + 1));
16+
ans.get(i).add(1);
17+
for (int j = 1; j < i; j++) {
18+
ans.get(i).add(ans.get(i - 1).get(j - 1) + ans.get(i - 1).get(j));
19+
}
20+
ans.get(i).add(1);
21+
}
22+
return ans;
23+
}
24+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-08-01 23:51:32
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-08-02 00:01:53
6+
'''
7+
from typing import List
8+
9+
class Solution:
10+
def generate(self, numRows: int) -> List[List[int]]:
11+
ans = [[1] for _ in range(numRows)]
12+
for i in range(1, numRows):
13+
for j in range(1, i):
14+
ans[i].append(ans[i - 1][j - 1] + ans[i - 1][j])
15+
ans[i].append(1)
16+
return ans
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-08-01 23:51:32
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-08-02 13:25:16
6+
*/
7+
impl Solution {
8+
pub fn generate(num_rows: i32) -> Vec<Vec<i32>> {
9+
let size = num_rows as usize;
10+
let mut ans = vec![vec![]; size];
11+
for i in 0..size {
12+
ans[i].resize(i + 1, 1);
13+
for j in 1..i {
14+
ans[i][j] = ans[i - 1][j - 1] + ans[i - 1][j];
15+
}
16+
}
17+
ans
18+
}
19+
}

Solutions/LeetCode 0118.杨辉三角.md

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,107 @@ public:
9090
9191
运行结果:耗时还挺少
9292
93-
![挺快的这次](https://cors.tisfy.eu.org/https://img-blog.csdnimg.cn/062fef3809fd4c878ac408f98b2f2d24.jpeg#pic_center)
93+
![挺快的这次](https://cors.letmefly.xyz/https://img-blog.csdnimg.cn/062fef3809fd4c878ac408f98b2f2d24.jpeg#pic_center)
94+
95+
#### Python
96+
97+
```python
98+
'''
99+
Author: LetMeFly
100+
Date: 2025-08-01 23:51:32
101+
LastEditors: LetMeFly.xyz
102+
LastEditTime: 2025-08-02 00:01:53
103+
'''
104+
from typing import List
105+
106+
class Solution:
107+
def generate(self, numRows: int) -> List[List[int]]:
108+
ans = [[1] for _ in range(numRows)]
109+
for i in range(1, numRows):
110+
for j in range(1, i):
111+
ans[i].append(ans[i - 1][j - 1] + ans[i - 1][j])
112+
ans[i].append(1)
113+
return ans
114+
```
115+
116+
#### Java
117+
118+
```java
119+
/*
120+
* @Author: LetMeFly
121+
* @Date: 2025-08-01 23:51:32
122+
* @LastEditors: LetMeFly.xyz
123+
* @LastEditTime: 2025-08-02 12:47:48
124+
*/
125+
import java.util.List;
126+
import java.util.ArrayList;
127+
128+
class Solution {
129+
public List<List<Integer>> generate(int numRows) {
130+
List<List<Integer>> ans = new ArrayList<>(numRows);
131+
ans.add(List.of(1));
132+
for (int i = 1; i < numRows; i++) {
133+
ans.add(new ArrayList<>(i + 1));
134+
ans.get(i).add(1);
135+
for (int j = 1; j < i; j++) {
136+
ans.get(i).add(ans.get(i - 1).get(j - 1) + ans.get(i - 1).get(j));
137+
}
138+
ans.get(i).add(1);
139+
}
140+
return ans;
141+
}
142+
}
143+
```
144+
145+
#### Go
146+
147+
```go
148+
/*
149+
* @Author: LetMeFly
150+
* @Date: 2025-08-01 23:51:32
151+
* @LastEditors: LetMeFly.xyz
152+
* @LastEditTime: 2025-08-02 13:12:32
153+
*/
154+
package main
155+
156+
func generate(numRows int) [][]int {
157+
ans := make([][]int, numRows)
158+
ans[0] = []int{1}
159+
for i := 1; i < numRows; i++ {
160+
ans[i] = make([]int, i + 1)
161+
ans[i][0] = 1
162+
for j := 1; j < i; j++ {
163+
ans[i][j] = ans[i - 1][j - 1] + ans[i - 1][j]
164+
}
165+
ans[i][i] = 1
166+
}
167+
return ans
168+
}
169+
```
170+
171+
#### Rust
172+
173+
```rust
174+
/*
175+
* @Author: LetMeFly
176+
* @Date: 2025-08-01 23:51:32
177+
* @LastEditors: LetMeFly.xyz
178+
* @LastEditTime: 2025-08-02 13:25:16
179+
*/
180+
impl Solution {
181+
pub fn generate(num_rows: i32) -> Vec<Vec<i32>> {
182+
let size = num_rows as usize;
183+
let mut ans = vec![vec![]; size];
184+
for i in 0..size {
185+
ans[i].resize(i + 1, 1);
186+
for j in 1..i {
187+
ans[i][j] = ans[i - 1][j - 1] + ans[i - 1][j];
188+
}
189+
}
190+
ans
191+
}
192+
}
193+
```
94194

95195
> 同步发文于CSDN,原创不易,转载请附上[原文链接](https://blog.letmefly.xyz/2022/07/17/LeetCode%200118.%E6%9D%A8%E8%BE%89%E4%B8%89%E8%A7%92/)哦~
96196
> Tisfy:[https://letmefly.blog.csdn.net/article/details/125829159](https://letmefly.blog.csdn.net/article/details/125829159)

Solutions/Other-English-LearningNotes-SomeWords.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ categories: [自用]
12941294
|||
12951295
|alienate|v. 离间,使疏远,使不友好,使(与某群体)格格不入|
12961296
|fort|n. 要塞;堡垒;兵营,军营|
1297-
|bulletin|n. 公告,告示;新闻快报;简报|
1297+
|<font color="#28bea0" title="二次复习">bulletin</font>|n. 公告,告示;新闻快报;简报|
12981298
|stevedore|n. 码头工人<br/>装船卸货|
12991299
|tar|n. 焦油,沥青<br/>用沥青抹,用柏油涂<br/>adj. 涂油柏油的|
13001300
|||
@@ -1326,6 +1326,13 @@ categories: [自用]
13261326
|embroider|v. 刺绣,加以润饰,对...添枝加叶|
13271327
|lipstick|n. 口红,唇膏,唇彩|
13281328
|governess|n. 家庭女教师|
1329+
|||
1330+
|convict|v. 定罪<br/>n. 服刑囚犯,已决犯|
1331+
|bugle|n. 号角,军号,喇叭|
1332+
|||
1333+
|dew|n. 露水<br/>v. 喷湿,结露水|
1334+
|impartial|adj. 无私的,公平的,中立的|
1335+
|centigrade|n. 摄氏温度<br/>adj. 摄氏的|
13291336

13301337
这个web要是能设计得可以闭眼(完全不睁眼)键盘控制背单词就好了。
13311338

Solutions/Other-Japanese-LearningNotes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ xx型
162162
|買い(かい)||
163163
|入れ(いれ)|预约(v.)|
164164
|予約(よやく)|预约(n.)|
165+
|セール(sale)|促销|
165166
|返品(へんぴん)|退货|
166167
|捨て(すて)||
167168
|交換(こうかん)|更换|
@@ -333,6 +334,7 @@ xx型
333334
|厚い(あつい)|厚的|
334335
|薄い(うすい)|薄的|
335336
|浮わ浮わ(ふわふわ)|软的|
337+
|柔らかい(やわらかい)|柔软的|
336338
|硬い(かたい)|硬的|
337339
|ふとい|粗的|
338340
|細い(ほそい)|细的|
@@ -555,7 +557,9 @@ xx型
555557
|服(ふく)|衣服|
556558
|洋服(ようふく)|衣服|
557559
|ドレス(dress)|裙子/礼服|
560+
|ワンピース(one-piece)|连衣裙|
558561
|ネクタイ|领带|
562+
|マフラー(muffler)|围巾|
559563
|スーツ|西服|
560564
|ハンカチ|手帕|
561565
|帽子(ぼうし)|帽子|
@@ -980,6 +984,7 @@ xx型
980984
|お勧め(おすすめ)|推荐|
981985
|大丈夫(だいじょうぶ)|没问题|
982986
|確認(かくにん)|确认|
987+
|似合い(にあい)|合适|
983988
|||
984989
|牛肉(ぎゅうにく)|牛肉|
985990
|豚肉(ぶたにく)|猪肉|

newSolution.py

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Author: LetMeFly
33
Date: 2022-07-03 11:21:14
44
LastEditors: LetMeFly.xyz
5-
LastEditTime: 2025-07-31 10:47:13
5+
LastEditTime: 2025-08-03 20:07:03
66
Command: python newSolution.py 102. 二叉树的层序遍历
77
What's more: 当前仅支持数字开头的题目
88
What's more: 代码结构写的很混乱 - 想单文件实现所有操作
@@ -99,6 +99,7 @@ def getPlatform():
9999
issueNum = int(issueCreateResult.split('\n')[0].split('/')[-1])
100100
else:
101101
os.popen(f'gh issue edit {issueNum} --add-label "solving"') # 这里暂不read等待popen执行完毕,这里的小异步是被允许的
102+
os.popen(f'gh issue comment {issueNum} -b "hello #{issueNum} you are not alone now."')
102103

103104
input('代码写完后按回车生成题解模板:')
104105

@@ -185,31 +186,33 @@ def refreshPublistTime(solution: str) -> str:
185186
print(solution)
186187

187188
solutionName = "Solutions/LeetCode {0:04d}.{1}.md".format(num, title)
188-
with open(solutionName, "x", encoding="utf-8") as f:
189-
f.write(solution)
189+
solutionExists = os.path.exists(solutionName)
190+
if not solutionExists:
191+
with open(solutionName, "w", encoding="utf-8") as f:
192+
f.write(solution)
190193

191-
print("请编辑题解: “{0}”,注意不要更改文件前5行".format(solutionName))
194+
print("请编辑题解: “{0}”,注意不要更改文件前5行".format(solutionName))
192195

193-
print("请去掉可能的由其他插件自动生成的头部注释信息,并保存你所编辑的题解")
194-
csdnid = input("请输入CSDN题解文章的id(11022152):")
195-
solutionURLcs = "https://letmefly.blog.csdn.net/article/details/{0}".format(csdnid)
196+
print("请去掉可能的由其他插件自动生成的头部注释信息,并保存你所编辑的题解")
197+
csdnid = input("请输入CSDN题解文章的id(11022152):")
198+
solutionURLcs = "https://letmefly.blog.csdn.net/article/details/{0}".format(csdnid)
196199

197-
with open(solutionName, "r", encoding="utf-8") as f:
198-
solution = f.read()
200+
with open(solutionName, "r", encoding="utf-8") as f:
201+
solution = f.read()
199202

200-
solution = solution.replace("--------------------------", csdnid)
201-
# solution = solution.replace("--------------------------", csdnid)
203+
solution = solution.replace("--------------------------", csdnid)
204+
# solution = solution.replace("--------------------------", csdnid)
202205

203-
with open(solutionName, "w", encoding="utf-8") as f:
204-
f.write(solution)
206+
with open(solutionName, "w", encoding="utf-8") as f:
207+
f.write(solution)
205208

206-
print("请重新复制所有的题解内容,并粘贴到CSDN中发布")
207-
print("请在LeetCode中新建、编辑并发布题解")
209+
print("请重新复制所有的题解内容,并粘贴到CSDN中发布")
210+
print("请在LeetCode中新建、编辑并发布题解")
208211

209-
solutionURLlc = input("LeetCode题解的url: ")
212+
solutionURLlc = input("LeetCode题解的url: ")
210213

211-
with open("README.md", "r", encoding="utf-8") as f:
212-
readme = f.read()
214+
with open("README.md", "r", encoding="utf-8") as f:
215+
readme = f.read()
213216

214217
def readmeNewLine(readme: str) -> str:
215218
splited = readme.split("\n")
@@ -260,10 +263,16 @@ def getProblemUrl():
260263
splited.insert(i, generateNewLine())
261264
return "\n".join(splited)
262265

263-
readme = readmeNewLine(readme)
264-
print(readme)
265-
with open("README.md", "w", encoding="utf-8") as f:
266-
f.write(readme)
266+
if not solutionExists:
267+
readme = readmeNewLine(readme)
268+
print(readme)
269+
with open("README.md", "w", encoding="utf-8") as f:
270+
f.write(readme)
271+
272+
if solutionExists:
273+
gitCommitMsgPrefix = f'update: 添加问题“{num}.{title}”的代码(并更新其题解)'
274+
else:
275+
gitCommitMsgPrefix = f'update: 添加问题“{num}.{title}”的代码和题解'
267276

268277
# commit push pr merge delete-branch
269278
os.system('git add .')
@@ -277,7 +286,7 @@ def getPrOrIssueMaxNum(prOrIssue: str) -> int: # (#811)
277286
return data[0]['number']
278287
lastNum = max(getPrOrIssueMaxNum('pr'), getPrOrIssueMaxNum('issue'))
279288
print(lastNum)
280-
commitMsg = f'update: 添加问题“{num}.{title}”的代码和题解(#{lastNum + 1})'
289+
commitMsg = f'{gitCommitMsgPrefix} (#{lastNum + 1})'
281290
if os.path.exists('.commitmsg') and os.path.isfile('.commitmsg'): # (#795)
282291
with open('.commitmsg', 'r', encoding='utf-8') as f:
283292
commitMsgFromfile = f.read()
@@ -286,7 +295,7 @@ def getPrOrIssueMaxNum(prOrIssue: str) -> int: # (#811)
286295
commitMsg += commitMsgFromfile
287296
subprocess.run(['git', 'commit', '-s', '-m', commitMsg]) # os.system('git commit -s -m "{msg}"')的话没法评论多行
288297
os.system(f'git push --set-upstream origin {num}')
289-
cmd = f'gh pr create -H {num} -t "添加问题“{num}.{title}”的代码和题解" -b "By [newSolution.py](https://github.com/LetMeFly666/LeetCode/blob/{lastSHA}/newSolution.py) using GH on {getPlatform()} | close: #{issueNum}" -l "题解" -a "@me"' # -H branch可能是 新版/旧版/Mac 所需的属性,并没有默认使用当前分支诶
298+
cmd = f'gh pr create -H {num} -t "{gitCommitMsgPrefix}" -b "By [newSolution.py](https://github.com/LetMeFly666/LeetCode/blob/{lastSHA}/newSolution.py) using GH on {getPlatform()} | close: #{issueNum}" -l "题解" -a "@me"' # -H branch可能是 新版/旧版/Mac 所需的属性,并没有默认使用当前分支诶
290299
print(cmd)
291300
prResult = os.popen(cmd).read()
292301
print(prResult)

0 commit comments

Comments
 (0)