更新 0349.两个数组的交集 排版格式修复

This commit is contained in:
jinbudaily
2023-07-19 14:30:12 +08:00
parent c628aa65d4
commit 19dfa98e4f

View File

@ -10,7 +10,7 @@
> 如果哈希值比较少、特别分散、跨度非常大,使用数组就造成空间的极大浪费! > 如果哈希值比较少、特别分散、跨度非常大,使用数组就造成空间的极大浪费!
## 349. 两个数组的交集 # 349. 两个数组的交集
[力扣题目链接](https://leetcode.cn/problems/intersection-of-two-arrays/) [力扣题目链接](https://leetcode.cn/problems/intersection-of-two-arrays/)
@ -22,9 +22,11 @@
输出结果中的每个元素一定是唯一的。 输出结果中的每个元素一定是唯一的。
我们可以不考虑输出结果的顺序。 我们可以不考虑输出结果的顺序。
## 思路 ## 算法公开课
关于本题,我录制了讲解视频[学透哈希表set使用有技巧Leetcode349. 两个数组的交集](https://www.bilibili.com/video/BV1ba411S7wu)看视频配合题解,事半功倍 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[学透哈希表set使用有技巧Leetcode349. 两个数组的交集](https://www.bilibili.com/video/BV1ba411S7wu)相信结合视频再看本篇题解,更有助于大家对本题的理解**
## 思路
这道题目主要要学会使用一种哈希数据结构unordered_set这个数据结构可以解决很多类似的问题。 这道题目主要要学会使用一种哈希数据结构unordered_set这个数据结构可以解决很多类似的问题。
@ -118,8 +120,7 @@ public:
## 其他语言版本 ## 其他语言版本
### Java
Java
```Java ```Java
import java.util.HashSet; import java.util.HashSet;
@ -159,8 +160,9 @@ class Solution {
} }
``` ```
Python3 ### Python3
(版本一) 使用字典和集合 (版本一) 使用字典和集合
```python ```python
class Solution: class Solution:
def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
@ -206,7 +208,8 @@ class Solution:
``` ```
Go ### Go
```go ```go
func intersection(nums1 []int, nums2 []int) []int { func intersection(nums1 []int, nums2 []int) []int {
set:=make(map[int]struct{},0) // 用map模拟set set:=make(map[int]struct{},0) // 用map模拟set
@ -227,7 +230,7 @@ func intersection(nums1 []int, nums2 []int) []int {
} }
``` ```
javaScript: ### JavaScript:
```js ```js
/** /**
@ -255,7 +258,7 @@ var intersection = function(nums1, nums2) {
}; };
``` ```
TypeScript: ### TypeScript:
版本一(正常解法): 版本一(正常解法):
@ -280,7 +283,7 @@ function intersection(nums1: number[], nums2: number[]): number[] {
}; };
``` ```
Swift ### Swift
```swift ```swift
func intersection(_ nums1: [Int], _ nums2: [Int]) -> [Int] { func intersection(_ nums1: [Int], _ nums2: [Int]) -> [Int] {
@ -298,7 +301,8 @@ func intersection(_ nums1: [Int], _ nums2: [Int]) -> [Int] {
} }
``` ```
PHP: ### PHP:
```php ```php
class Solution { class Solution {
/** /**
@ -327,7 +331,8 @@ class Solution {
} }
``` ```
Rust: ### Rust:
```rust ```rust
use std::collections::HashSet; use std::collections::HashSet;
impl Solution { impl Solution {
@ -363,7 +368,8 @@ impl Solution {
} }
``` ```
C: ### C:
```C ```C
int* intersection1(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize){ int* intersection1(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize){
@ -394,7 +400,7 @@ int* intersection1(int* nums1, int nums1Size, int* nums2, int nums2Size, int* re
} }
``` ```
Scala: ### Scala:
正常解法: 正常解法:
```scala ```scala
@ -439,8 +445,8 @@ object Solution {
``` ```
### C#:
C#:
```csharp ```csharp
public int[] Intersection(int[] nums1, int[] nums2) { public int[] Intersection(int[] nums1, int[] nums2) {
if(nums1==null||nums1.Length==0||nums2==null||nums1.Length==0) if(nums1==null||nums1.Length==0||nums2==null||nums1.Length==0)
@ -461,11 +467,10 @@ C#:
``` ```
## 相关题目 ## 相关题目
* 350.两个数组的交集 II * [350.两个数组的交集 II](https://leetcode.cn/problems/intersection-of-two-arrays-ii/)
<p align="center"> <p align="center">
<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>