You are viewing a single comment's thread. Return to all comments →
Here is my Java 15 solution:
import java.util.*; class Result { public static String nimGame(List<Integer> piles) { int remaining = piles.stream() .reduce(0, (pile1, pile2) -> pile1 ^ pile2); return (remaining == 0 ? "Second" : "First"); } } public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int g = scanner.nextInt(); for (int i = 0; i < g; i++) { int n = scanner.nextInt(); List<Integer> list = new ArrayList<>(n); for (int j = 0; j < n; j++) { int current = scanner.nextInt(); list.add(current); } String result = Result.nimGame(list); System.out.println(result); } scanner.close(); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Introduction to Nim Game
You are viewing a single comment's thread. Return to all comments →
Here is my Java 15 solution: