Given two arrays, write a function to compute their intersection.
Example:
Given nums1 =[1, 2, 2, 1] , nums2 = [2, 2] , return [2, 2] .
Given nums1 =
Note:
- Each element in the result should appear as many times as it shows in both arrays.
- The result can be in any order.
這題是 349. Intersection of Two Arrays 的衍生題
差別在於,這次重覆了幾次,答案裡面就要有幾次
思考方向不變,只是改用 hash map,因為要記錄幾次
code如下
C++
Java
Kotlin
沒有留言:
張貼留言