diff --git a/problems/0454.四数相加II.md b/problems/0454.四数相加II.md index 4a16d4f4..90c37334 100644 --- a/problems/0454.四数相加II.md +++ b/problems/0454.四数相加II.md @@ -34,10 +34,12 @@ 1. (0, 0, 0, 1) -> A[0] + B[0] + C[0] + D[1] = 1 + (-2) + (-1) + 2 = 0 2. (1, 1, 0, 0) -> A[1] + B[1] + C[0] + D[0] = 2 + (-1) + (-1) + 0 = 0 +## 算法公开课 -# 思路 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[学透哈希表,map使用有技巧!LeetCode:454.四数相加II](https://www.bilibili.com/video/BV1Md4y1Q7Yh),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 -本题视频讲解:[学透哈希表,map使用有技巧!LeetCode:454.四数相加II](https://www.bilibili.com/video/BV1Md4y1Q7Yh),结合视频在看本题解,事半功倍。 + +## 思路 本题咋眼一看好像和[0015.三数之和](https://programmercarl.com/0015.三数之和.html),[0018.四数之和](https://programmercarl.com/0018.四数之和.html)差不多,其实差很多。 @@ -92,8 +94,8 @@ public: ## 其他语言版本 +### Java: -Java: ```Java class Solution { public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) { @@ -117,8 +119,9 @@ class Solution { } ``` -Python: +### Python: (版本一) 使用字典 + ```python class Solution(object): def fourSumCount(self, nums1, nums2, nums3, nums4): @@ -179,7 +182,7 @@ class Solution: return cnt ``` -Go: +### Go: ```go func fourSumCount(nums1 []int, nums2 []int, nums3 []int, nums4 []int) int { @@ -201,7 +204,7 @@ func fourSumCount(nums1 []int, nums2 []int, nums3 []int, nums4 []int) int { } ``` -javaScript: +### JavaScript: ```js /** @@ -233,7 +236,7 @@ var fourSumCount = function(nums1, nums2, nums3, nums4) { }; ``` -TypeScript: +### TypeScript: ```typescript function fourSumCount(nums1: number[], nums2: number[], nums3: number[], nums4: number[]): number { @@ -258,7 +261,7 @@ function fourSumCount(nums1: number[], nums2: number[], nums3: number[], nums4: }; ``` -PHP: +### PHP: ```php class Solution { @@ -291,8 +294,8 @@ class Solution { } ``` +### Swift: -Swift: ```swift func fourSumCount(_ nums1: [Int], _ nums2: [Int], _ nums3: [Int], _ nums4: [Int]) -> Int { // ab和: ab和出现次数 @@ -316,7 +319,8 @@ func fourSumCount(_ nums1: [Int], _ nums2: [Int], _ nums3: [Int], _ nums4: [Int] } ``` -Rust: +### Rust: + ```rust use std::collections::HashMap; impl Solution { @@ -342,8 +346,8 @@ impl Solution { } ``` +### Scala: -Scala: ```scala object Solution { // 导包 @@ -380,7 +384,8 @@ object Solution { } ``` -C#: +### C#: + ```csharp public int FourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) { Dictionary dic = new Dictionary(); @@ -411,3 +416,4 @@ public int FourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) { +