Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0e203a7

Browse files
Leetcode solution to the problem: find-the-difference-of-two-arrays
1 parentaddb959 commit0e203a7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::collections::HashSet;
2+
3+
implSolution{
4+
pubfnfind_difference(nums1:Vec<i32>,nums2:Vec<i32>) ->Vec<Vec<i32>>{
5+
6+
let s1:HashSet<i32> = nums1.into_iter().collect();
7+
let s2:HashSet<i32> = nums2.into_iter().collect();
8+
9+
letmut r1:HashSet<i32> =HashSet::new();
10+
letmut r2:HashSet<i32> =HashSet::new();
11+
12+
for nin&s1{
13+
if !s2.contains(n){
14+
r1.insert(*n);
15+
}
16+
}
17+
18+
for nin&s2{
19+
if !s1.contains(n){
20+
r2.insert(*n);
21+
}
22+
}
23+
24+
vec![
25+
r1.into_iter().collect(),
26+
r2.into_iter().collect(),
27+
]
28+
29+
}
30+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp