Skip to content

Commit c687ec5

Browse files
committed
Runtime: 1 ms (Top 81.03%) | Memory: 2.20 MB (Top 63.79%)
1 parent 31c8aa0 commit c687ec5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Runtime: 1 ms (Top 81.03%) | Memory: 2.20 MB (Top 63.79%)
2+
3+
impl Solution {
4+
// array version
5+
pub fn intersect(nums1: Vec<i32>, nums2: Vec<i32>) -> Vec<i32> {
6+
let mut record = [0; 1001];
7+
for &n in nums1.iter() {
8+
record[n as usize] += 1;
9+
}
10+
let mut ans = Vec::new();
11+
for &n in nums2.iter() {
12+
if record[n as usize] != 0 {
13+
ans.push(n);
14+
record[n as usize] -= 1;
15+
}
16+
}
17+
ans
18+
}
19+
}

0 commit comments

Comments
 (0)