From b32c3bb8a8233ff11e7436319fa952da0195439f Mon Sep 17 00:00:00 2001 From: Bryce S <44215173+GHumorBS@users.noreply.github.com> Date: Thu, 26 Aug 2021 16:20:26 +0800 Subject: [PATCH] =?UTF-8?q?Update=200454.=E5=9B=9B=E6=95=B0=E7=9B=B8?= =?UTF-8?q?=E5=8A=A0II.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新python算法:明明用了defaultdict[key: int]默认value等于0,却仍要画蛇添足: value = hashmap.get(key) count += value or 0 这也太奇怪了8!!! --- problems/0454.四数相加II.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/problems/0454.四数相加II.md b/problems/0454.四数相加II.md index 7bb24e59..4e61dc2f 100644 --- a/problems/0454.四数相加II.md +++ b/problems/0454.四数相加II.md @@ -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 ```