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
| class Solution { public int[] circularGameLosers(int n, int k) { int[] countMap = new int[n]; int index = 0, steps = 1; while (true) { if (++countMap[index] == 2) { break; } index += steps * k; index = index % n; steps++; }
List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) { if (countMap[i] == 0) { list.add(i); } } int[] res = new int[list.size()]; for (int i = 0; i < list.size(); i++) { res[i] = list.get(i) + 1; } return res; } }
|
References
2682. Find the Losers of the Circular Game