forked from BigEggStudy/LeetCode-CS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1213-IntersectionOfThreeSortedArrays.cs
More file actions
32 lines (27 loc) · 1016 Bytes
/
1213-IntersectionOfThreeSortedArrays.cs
File metadata and controls
32 lines (27 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//-----------------------------------------------------------------------------
// Runtime: 236ms
// Memory Usage: 32.4 MB
// Link: https://leetcode.com/submissions/detail/327380202/
//-----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
namespace LeetCode
{
public class _1213_IntersectionOfThreeSortedArrays
{
public IList<int> ArraysIntersection(int[] arr1, int[] arr2, int[] arr3)
{
int i = 0, j = 0;
int length = Math.Min(Math.Min(arr1.Length, arr2.Length), arr3.Length);
var result = new List<int>();
for (int k = 0; k < length; k++)
{
while (i < length && arr1[i] < arr3[k]) i++;
while (j < length && arr2[j] < arr3[k]) j++;
if (i < length && j < length && arr1[i] == arr2[j] && arr1[i] == arr3[k])
result.Add(arr1[i]);
}
return result;
}
}
}