intersection of Three Sorted Arrays
给三个sorted array, 问里面的相交元素. 直接counting就可以.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
class Solution { public List<Integer> arraysIntersection(int[] arr1, int[] arr2, int[] arr3) { int[] count = new int[2001]; for(int n : arr1) count[n] ++; for(int n : arr2) count[n] ++; for(int n : arr3) count[n] ++; List<Integer> res = new ArrayList<>(); for(int i = 0; i < count.length; i++){ if(count[i] == 3) res.add(i); } return res; } } |