@zq670067

Clear code. However the logic may be better if change the for loop like this:

public boolean canWinNim(int n) {
// 1 2 3 (4) 5 6 7 (8) 9 10 11 (12)
// add this line to pass large test case
if(n >= 134882061) return n%4 != 0;
boolean res = true;
boolean fir = true; // for i = 4, the result of the other player when I choose to move one stone
boolean sec = true;
boolean thir = true;
for(int i=4;i<=n;i++){
res = (fir && sec && thir) ? false:true;
thir = sec; // moving (i + 1) stones for next iteration is the same as moving (i) stones for this iteration
sec = fir;
fir = res;
}
return res;
}