1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| class Solution { public int flipgame(int[] fronts, int[] backs) { Set<Integer> blackNumSet = new HashSet<>(); for (int i = 0; i < fronts.length; i++) { if (fronts[i] == backs[i]) { blackNumSet.add(fronts[i]); } }
int res = Integer.MAX_VALUE; for (int num : fronts) { if (!blackNumSet.contains(num)) { res = Math.min(res, num); } } for (int num : backs) { if (!blackNumSet.contains(num)) { res = Math.min(res, num); } }
return res == Integer.MAX_VALUE ? 0 : res; } }
|