mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Update 0454.四数相加II.md
更新python算法:明明用了defaultdict[key: int]默认value等于0,却仍要画蛇添足: value = hashmap.get(key) count += value or 0 这也太奇怪了8!!!
This commit is contained in:
@ -161,15 +161,9 @@ class Solution(object):
|
|||||||
# count=0
|
# count=0
|
||||||
# for x3 in nums3:
|
# for x3 in nums3:
|
||||||
# for x4 in nums4:
|
# for x4 in nums4:
|
||||||
# key = -x3-x4
|
# key = 0 - x3 - x4
|
||||||
# value = hashmap.get(key)
|
# value = hashmap[key] # 若差值(key)不存在,则value被赋值0
|
||||||
|
# count += value
|
||||||
# dict的get方法会返回None(key不存在)或者key对应的value
|
|
||||||
# 所以如果value==0,就会继续执行or,count+0,否则就会直接加value
|
|
||||||
# 这样就不用去写if判断了
|
|
||||||
|
|
||||||
# count += value or 0
|
|
||||||
|
|
||||||
# return count
|
# return count
|
||||||
|
|
||||||
```
|
```
|
||||||
|
Reference in New Issue
Block a user