Skip to content

Commit 37e7d73

Browse files
Update
1 parent 266702c commit 37e7d73

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+64
-60
lines changed

problems/0020.有效的括号.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class Solution {
159159
```
160160

161161
Python:
162-
```python3
162+
```python
163163
# 方法一,仅使用栈,更省空间
164164
class Solution:
165165
def isValid(self, s: str) -> bool:
@@ -180,7 +180,7 @@ class Solution:
180180
return True if not stack else False
181181
```
182182

183-
```python3
183+
```python
184184
# 方法二,使用字典
185185
class Solution:
186186
def isValid(self, s: str) -> bool:

problems/0027.移除元素.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class Solution {
142142

143143
Python:
144144

145-
```python3
145+
```python
146146
class Solution:
147147
"""双指针法
148148
时间复杂度:O(n)

problems/0035.搜索插入位置.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func searchInsert(nums []int, target int) int {
246246
```
247247

248248
### Python
249-
```python3
249+
```python
250250
class Solution:
251251
def searchInsert(self, nums: List[int], target: int) -> int:
252252
left, right = 0, len(nums) - 1

problems/0039.组合总和.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class Solution {
264264

265265
## Python
266266
**回溯**
267-
```python3
267+
```python
268268
class Solution:
269269
def __init__(self):
270270
self.path = []
@@ -296,7 +296,7 @@ class Solution:
296296
self.path.pop() # 回溯
297297
```
298298
**剪枝回溯**
299-
```python3
299+
```python
300300
class Solution:
301301
def __init__(self):
302302
self.path = []

problems/0040.组合总和II.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ class Solution {
334334

335335
## Python
336336
**回溯+巧妙去重(省去使用used**
337-
```python3
337+
```python
338338
class Solution:
339339
def __init__(self):
340340
self.paths = []
@@ -374,7 +374,7 @@ class Solution:
374374
sum_ -= candidates[i] # 回溯,为了下一轮for loop
375375
```
376376
**回溯+去重(使用used)**
377-
```python3
377+
```python
378378
class Solution:
379379
def __init__(self):
380380
self.paths = []

problems/0042.接雨水.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ class Solution:
491491
return res
492492
```
493493
动态规划
494-
```python3
494+
```python
495495
class Solution:
496496
def trap(self, height: List[int]) -> int:
497497
leftheight, rightheight = [0]*len(height), [0]*len(height)

problems/0046.全排列.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class Solution:
243243
usage_list[i] = False
244244
```
245245
**回溯+丢掉usage_list**
246-
```python3
246+
```python
247247
class Solution:
248248
def __init__(self):
249249
self.path = []

problems/0059.螺旋矩阵II.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ class Solution {
188188
}
189189
```
190190

191-
python:
191+
python3:
192192

193-
```python3
193+
```python
194194
class Solution:
195195

196196
def generateMatrix(self, n: int) -> List[List[int]]:

problems/0070.爬楼梯完全背包版本.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ class Solution {
143143
}
144144
```
145145

146-
Python
146+
Python3
147147

148148

149-
```python3
149+
```python
150150
class Solution:
151151
def climbStairs(self, n: int) -> int:
152152
dp = [0]*(n + 1)

problems/0077.组合优化.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class Solution {
174174
```
175175

176176
Python:
177-
```python3
177+
```python
178178
class Solution:
179179
def combine(self, n: int, k: int) -> List[List[int]]:
180180
res=[] #存放符合条件结果的集合

problems/0078.子集.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class Solution {
203203
```
204204

205205
## Python
206-
```python3
206+
```python
207207
class Solution:
208208
def __init__(self):
209209
self.path: List[int] = []

problems/0084.柱状图中最大的矩形.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ class Solution {
277277
}
278278
```
279279

280-
Python:
280+
Python3:
281281

282-
```python3
282+
```python
283283

284284
# 双指针;暴力解法(leetcode超时)
285285
class Solution:

problems/0093.复原IP地址.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ class Solution(object):
339339
```
340340

341341
python3:
342-
```python3
342+
```python
343343
class Solution:
344344
def __init__(self):
345345
self.result = []

problems/0102.二叉树的层序遍历.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ public:
8383
};
8484
```
8585
86-
python代码
86+
python3代码
8787
8888
89-
```python3
89+
```python
9090
9191
class Solution:
9292
"""二叉树层序遍历迭代解法"""

problems/0108.将有序数组转换为二叉搜索树.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class Solution {
305305
## Python
306306
**递归**
307307

308-
```python3
308+
```python
309309
# Definition for a binary tree node.
310310
# class TreeNode:
311311
# def __init__(self, val=0, left=None, right=None):

problems/0110.平衡二叉树.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ class Solution {
497497
## Python
498498

499499
递归法:
500-
```python3
500+
```python
501501
# Definition for a binary tree node.
502502
# class TreeNode:
503503
# def __init__(self, val=0, left=None, right=None):

problems/0129.求根到叶子节点数字之和.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class Solution {
217217
```
218218

219219
Python:
220-
```python3
220+
```python
221221
class Solution:
222222
def sumNumbers(self, root: TreeNode) -> int:
223223
res = 0

problems/0131.分割回文串.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ class Solution {
289289

290290
## Python
291291
**回溯+正反序判断回文串**
292-
```python3
292+
```python
293293
class Solution:
294294
def __init__(self):
295295
self.paths = []
@@ -326,7 +326,7 @@ class Solution:
326326
continue
327327
```
328328
**回溯+函数判断回文串**
329-
```python3
329+
```python
330330
class Solution:
331331
def __init__(self):
332332
self.paths = []

problems/0188.买卖股票的最佳时机IV.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class Solution:
271271
return dp[-1][2*k]
272272
```
273273
版本二
274-
```python3
274+
```python
275275
class Solution:
276276
def maxProfit(self, k: int, prices: List[int]) -> int:
277277
if len(prices) == 0: return 0

problems/0257.二叉树的所有路径.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ class Solution:
436436

437437
迭代法:
438438

439-
```python3
439+
```python
440440
from collections import deque
441441

442442

problems/0279.完全平方数.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class Solution {
207207

208208
Python:
209209

210-
```python3
210+
```python
211211
class Solution:
212212
def numSquares(self, n: int) -> int:
213213
'''版本一,先遍历背包, 再遍历物品'''

problems/0322.零钱兑换.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class Solution {
207207
208208
Python:
209209
210-
```python3
210+
```python
211211
class Solution:
212212
def coinChange(self, coins: List[int], amount: int) -> int:
213213
'''版本一'''

problems/0337.打家劫舍III.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ Python:
288288

289289
> 暴力递归
290290
291-
```python3
291+
```python
292292

293293
# Definition for a binary tree node.
294294
# class TreeNode:
@@ -315,7 +315,7 @@ class Solution:
315315

316316
> 记忆化递归
317317
318-
```python3
318+
```python
319319

320320
# Definition for a binary tree node.
321321
# class TreeNode:
@@ -345,7 +345,7 @@ class Solution:
345345
```
346346

347347
> 动态规划
348-
```python3
348+
```python
349349
# Definition for a binary tree node.
350350
# class TreeNode:
351351
# def __init__(self, val=0, left=None, right=None):

problems/0376.摆动序列.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ class Solution {
228228

229229
### Python
230230

231-
```python3
231+
```python
232232
class Solution:
233233
def wiggleMaxLength(self, nums: List[int]) -> int:
234234
preC,curC,res = 0,0,1 #题目里nums长度大于等于1,当长度为1时,其实到不了for循环里去,所以不用考虑nums长度

problems/0383.赎金信.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class Solution(object):
209209

210210
Python写法四:
211211

212-
```python3
212+
```python
213213
class Solution:
214214
def canConstruct(self, ransomNote: str, magazine: str) -> bool:
215215
c1 = collections.Counter(ransomNote)

problems/0404.左叶子之和.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class Solution {
229229
## Python
230230

231231
**递归后序遍历**
232-
```python3
232+
```python
233233
class Solution:
234234
def sumOfLeftLeaves(self, root: TreeNode) -> int:
235235
if not root:
@@ -246,7 +246,7 @@ class Solution:
246246
```
247247

248248
**迭代**
249-
```python3
249+
```python
250250
class Solution:
251251
def sumOfLeftLeaves(self, root: TreeNode) -> int:
252252
"""

problems/0455.分发饼干.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class Solution {
146146
```
147147

148148
### Python
149-
```python3
149+
```python
150150
class Solution:
151151
# 思路1:优先考虑胃饼干
152152
def findContentChildren(self, g: List[int], s: List[int]) -> int:

problems/0463.岛屿的周长.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Python:
124124
### 解法1:
125125
扫描每个cell,如果当前位置为岛屿 grid[i][j] == 1, 从当前位置判断四边方向,如果边界或者是水域,证明有边界存在,res矩阵的对应cell加一。
126126

127-
```python3
127+
```python
128128
class Solution:
129129
def islandPerimeter(self, grid: List[List[int]]) -> int:
130130

problems/0474.一和零.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class Solution {
193193
```
194194

195195
Python:
196-
```python3
196+
```python
197197
class Solution:
198198
def findMaxForm(self, strs: List[str], m: int, n: int) -> int:
199199
dp = [[0] * (n + 1) for _ in range(m + 1)] # 默认初始化0

problems/0491.递增子序列.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class Solution {
233233

234234
python3
235235
**回溯**
236-
```python3
236+
```python
237237
class Solution:
238238
def __init__(self):
239239
self.paths = []
@@ -270,7 +270,7 @@ class Solution:
270270
self.path.pop()
271271
```
272272
**回溯+哈希表去重**
273-
```python3
273+
```python
274274
class Solution:
275275
def __init__(self):
276276
self.paths = []

problems/0494.目标和.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,16 @@ dp[j] 表示:填满j(包括j)这么大容积的包,有dp[j]种方法
160160

161161
那么只要搞到nums[i]的话,凑成dp[j]就有dp[j - nums[i]] 种方法。
162162

163-
举一个例子,nums[i] = 2: dp[3],填满背包容量为3的话,有dp[3]种方法。
164163

165-
那么只需要搞到一个2(nums[i]),有dp[3]方法可以凑齐容量为3的背包,相应的就有多少种方法可以凑齐容量为5的背包。
164+
例如:dp[j],j 为5,
166165

167-
那么需要把 这些方法累加起来就可以了,dp[j] += dp[j - nums[i]]
166+
* 已经有一个1(nums[i]) 的话,有 dp[4]种方法 凑成 dp[5]
167+
* 已经有一个2(nums[i]) 的话,有 dp[3]种方法 凑成 dp[5]
168+
* 已经有一个3(nums[i]) 的话,有 dp[2]中方法 凑成 dp[5]
169+
* 已经有一个4(nums[i]) 的话,有 dp[1]中方法 凑成 dp[5]
170+
* 已经有一个5 (nums[i])的话,有 dp[0]中方法 凑成 dp[5]
171+
172+
那么凑整dp[5]有多少方法呢,也就是把 所有的 dp[j - nums[i]] 累加起来。
168173

169174
所以求组合类问题的公式,都是类似这种:
170175

problems/0496.下一个更大元素I.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ class Solution {
222222
}
223223
}
224224
```
225-
Python
226-
```python3
225+
Python3
226+
```python
227227
class Solution:
228228
def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]:
229229
result = [-1]*len(nums1)

0 commit comments

Comments
 (0)