-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindCommonElement.cs
More file actions
44 lines (41 loc) · 851 Bytes
/
FindCommonElement.cs
File metadata and controls
44 lines (41 loc) · 851 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
33
34
35
36
37
38
39
40
41
42
43
44
using System;
namespace ConsoleApp168
{
class Program
{
static void Main(string[] args)
{
int[] arr1 = {1, 5};
int[] arr2 = {3, 4, 5, 5, 10};
int[] arr3 = {5, 5, 10, 20};
Console.WriteLine("Common elements are :: ");
findCommon(arr1, arr2, arr3);
}
private static void findCommon(int[] arr1, int[] arr2, int[] arr3)
{
int i = 0, j = 0, k = 0;
while (i<arr1.Length && j < arr2.Length && k <arr3.Length)
{
if (arr1[i] == arr2[j] && arr2[j] == arr3[k])
{
Console.WriteLine(arr1[i] + " ");
i++;
j++;
k++;
}
else if(arr1[i] < arr2[j])
{
i++;
}
else if (arr2[j] < arr3[k])
{
j++;
}
else
{
k++;
}
}
}
}
}