m*****a 发帖数: 5 | 1 there are 2 integer arrays a and b ;
how do find the intersection of these two arrays and keep the order of array
a?
Has any one posted this question before? | s***y 发帖数: 124 | 2 Build a HashMap using b,
Loop through a, check if element is in the HashMap | m*****a 发帖数: 5 | 3 Thanks. then how do you handle the repeat of elements?
say; A { 1,5, 5, 8 , 7,6,5}
B: {2, 3, 5, 5, 9,22,7} | g*****g 发帖数: 34805 | 4 Use hashset
【在 m*****a 的大作中提到】 : Thanks. then how do you handle the repeat of elements? : say; A { 1,5, 5, 8 , 7,6,5} : B: {2, 3, 5, 5, 9,22,7}
| Z****e 发帖数: 2999 | 5 when you build HashMap with B, let the key be elements in B, value be its
number of duplications
when you scan A, reduce the number of duplication in map when you find a
match and remove it from HashMap when it's zero
【在 m*****a 的大作中提到】 : Thanks. then how do you handle the repeat of elements? : say; A { 1,5, 5, 8 , 7,6,5} : B: {2, 3, 5, 5, 9,22,7}
| m*****a 发帖数: 5 | |
|