mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
更新 0454.四数相加II 排版格式修复
This commit is contained in:
@ -34,10 +34,12 @@
|
|||||||
1. (0, 0, 0, 1) -> A[0] + B[0] + C[0] + D[1] = 1 + (-2) + (-1) + 2 = 0
|
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
|
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)差不多,其实差很多。
|
本题咋眼一看好像和[0015.三数之和](https://programmercarl.com/0015.三数之和.html),[0018.四数之和](https://programmercarl.com/0018.四数之和.html)差不多,其实差很多。
|
||||||
|
|
||||||
@ -92,8 +94,8 @@ public:
|
|||||||
|
|
||||||
## 其他语言版本
|
## 其他语言版本
|
||||||
|
|
||||||
|
### Java:
|
||||||
|
|
||||||
Java:
|
|
||||||
```Java
|
```Java
|
||||||
class Solution {
|
class Solution {
|
||||||
public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
|
public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
|
||||||
@ -117,8 +119,9 @@ class Solution {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Python:
|
### Python:
|
||||||
(版本一) 使用字典
|
(版本一) 使用字典
|
||||||
|
|
||||||
```python
|
```python
|
||||||
class Solution(object):
|
class Solution(object):
|
||||||
def fourSumCount(self, nums1, nums2, nums3, nums4):
|
def fourSumCount(self, nums1, nums2, nums3, nums4):
|
||||||
@ -179,7 +182,7 @@ class Solution:
|
|||||||
return cnt
|
return cnt
|
||||||
```
|
```
|
||||||
|
|
||||||
Go:
|
### Go:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func fourSumCount(nums1 []int, nums2 []int, nums3 []int, nums4 []int) int {
|
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
|
```js
|
||||||
/**
|
/**
|
||||||
@ -233,7 +236,7 @@ var fourSumCount = function(nums1, nums2, nums3, nums4) {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
TypeScript:
|
### TypeScript:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
function fourSumCount(nums1: number[], nums2: number[], nums3: number[], nums4: number[]): number {
|
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
|
```php
|
||||||
class Solution {
|
class Solution {
|
||||||
@ -291,8 +294,8 @@ class Solution {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Swift:
|
||||||
|
|
||||||
Swift:
|
|
||||||
```swift
|
```swift
|
||||||
func fourSumCount(_ nums1: [Int], _ nums2: [Int], _ nums3: [Int], _ nums4: [Int]) -> Int {
|
func fourSumCount(_ nums1: [Int], _ nums2: [Int], _ nums3: [Int], _ nums4: [Int]) -> Int {
|
||||||
// ab和: ab和出现次数
|
// ab和: ab和出现次数
|
||||||
@ -316,7 +319,8 @@ func fourSumCount(_ nums1: [Int], _ nums2: [Int], _ nums3: [Int], _ nums4: [Int]
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Rust:
|
### Rust:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
impl Solution {
|
impl Solution {
|
||||||
@ -342,8 +346,8 @@ impl Solution {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Scala:
|
||||||
|
|
||||||
Scala:
|
|
||||||
```scala
|
```scala
|
||||||
object Solution {
|
object Solution {
|
||||||
// 导包
|
// 导包
|
||||||
@ -380,7 +384,8 @@ object Solution {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
C#:
|
### C#:
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
public int FourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
|
public int FourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
|
||||||
Dictionary<int, int> dic = new Dictionary<int, int>();
|
Dictionary<int, int> dic = new Dictionary<int, int>();
|
||||||
@ -411,3 +416,4 @@ public int FourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
|
|||||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user