---
# System prepended metadata

title: 1213. Intersection of Three Sorted Arrays
tags: [Leetcode, FaceBook, Easy, Merge Sorted List]

---

# 1213. Intersection of Three Sorted Arrays
###### tags: `Leetcode` `Easy` `FaceBook` `Merge Sorted List`
Link: https://leetcode.com/problems/intersection-of-three-sorted-arrays/
## 思路
### 思路一 O(N) O(N)
brute force的思路是用hashmap记录每个数出现的次数，count=3，就放到答案里面
### 思路二 O(N) O(1)
三指针
一开始只想到两个指针，说啥也没想到用三个
用三个要注意一个问题就是else if要把=包含进去
## Code
```java=
class Solution {
    public List<Integer> arraysIntersection(int[] arr1, int[] arr2, int[] arr3) {
        List<Integer> ans = new ArrayList<>();
        int p1 = 0, p2 = 0, p3 = 0;
        while(p1!=arr1.length && p2!=arr2.length && p3!=arr3.length){
            if(arr1[p1]==arr2[p2] && arr2[p2]==arr3[p3]){ 
                ans.add(arr1[p1]);
                p1++;
                p2++;
                p3++;
            }
            else if(arr1[p1] <= Math.min(arr2[p2], arr3[p3])){
                p1++;
            }
            else if(arr2[p2] <= Math.min(arr1[p1], arr3[p3])){
                p2++;
            }
            else{
                p3++;
            }
        }
        return ans;
    }
}
```