Skip to content

Commit

Permalink
Update 0454.四数相加II.md
Browse files Browse the repository at this point in the history
更新python算法:明明用了defaultdict[key: int]默认value等于0,却仍要画蛇添足:
value = hashmap.get(key)
count += value or 0
这也太奇怪了8!!!
  • Loading branch information
casnz1601 authored Aug 26, 2021
1 parent 5b26e13 commit b32c3bb
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions problems/0454.四数相加II.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,9 @@ class Solution(object):
# count=0
# for x3 in nums3:
# for x4 in nums4:
# key = -x3-x4
# value = hashmap.get(key)

# dict的get方法会返回None(key不存在)或者key对应的value
# 所以如果value==0,就会继续执行or,count+0,否则就会直接加value
# 这样就不用去写if判断了

# count += value or 0

# key = 0 - x3 - x4
# value = hashmap[key] # 若差值(key)不存在,则value被赋值0
# count += value
# return count

```
Expand Down

0 comments on commit b32c3bb

Please sign in to comment.