Skip to content

Commit

Permalink
Merge pull request youngyangyang04#1019 from xiaofei-2020/hash6
Browse files Browse the repository at this point in the history
添加(0454.四数相加II.md):增加typescript版本
  • Loading branch information
youngyangyang04 authored Jan 21, 2022
2 parents 0893d45 + ed2f56f commit f4c9014
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions problems/0454.四数相加II.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<number, number> = 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 {
/**
Expand Down

0 comments on commit f4c9014

Please sign in to comment.