-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution822.cs
41 lines (35 loc) · 967 Bytes
/
Solution822.cs
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
using System.Text;
using LeetCode.DataStructures;
namespace LeetCode.Solutions;
public class Solution822
{
/// <summary>
/// 822. Card Flipping Game - Medium
/// <a href="https://leetcode.com/problems/card-flipping-game">See the problem</a>
/// </summary>
public int Flipgame(int[] fronts, int[] backs)
{
var n = fronts.Length;
var same = new HashSet<int>();
for (var i = 0; i < n; i++)
{
if (fronts[i] == backs[i])
{
same.Add(fronts[i]);
}
}
var result = int.MaxValue;
for (var i = 0; i < n; i++)
{
if (!same.Contains(fronts[i]))
{
result = Math.Min(result, fronts[i]);
}
if (!same.Contains(backs[i]))
{
result = Math.Min(result, backs[i]);
}
}
return result == int.MaxValue ? 0 : result;
}
}