From ed2f56fa28817edbfccd3d3bc38f07eac71a5f2b Mon Sep 17 00:00:00 2001 From: Steve2020 <841532108@qq.com> Date: Thu, 13 Jan 2022 20:32:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=880454.=E5=9B=9B?= =?UTF-8?q?=E6=95=B0=E7=9B=B8=E5=8A=A0II.md=EF=BC=89:=E5=A2=9E=E5=8A=A0typ?= =?UTF-8?q?escript=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0454.四数相加II.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/problems/0454.四数相加II.md b/problems/0454.四数相加II.md index 6853354c..352f693b 100644 --- a/problems/0454.四数相加II.md +++ b/problems/0454.四数相加II.md @@ -139,7 +139,7 @@ class Solution(object): return count -``` +``` Go: ```go @@ -192,8 +192,33 @@ var fourSumCount = function(nums1, nums2, nums3, nums4) { }; ``` +TypeScript: + +```typescript +function fourSumCount(nums1: number[], nums2: number[], nums3: number[], nums4: number[]): number { + let helperMap: Map = new Map(); + let resNum: number = 0; + let tempVal: number | undefined; + for (let i of nums1) { + for (let j of nums2) { + tempVal = helperMap.get(i + j); + helperMap.set(i + j, tempVal ? tempVal + 1 : 1); + } + } + for (let k of nums3) { + for (let l of nums4) { + tempVal = helperMap.get(0 - (k + l)); + if (tempVal) { + resNum += tempVal; + } + } + } + return resNum; +}; +``` PHP: + ```php class Solution { /**