We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 31c8aa0 commit c687ec5Copy full SHA for c687ec5
scripts/algorithms/I/Intersection of Two Arrays II/Intersection of Two Arrays II.rs
@@ -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