A simple solution


  • 3
    C
    1. for n = 1,2,3, you can win because you can take them all for the
      first shot
    2. for n = 4, you lose
    3. for n = 4 * 1 + (1, 2, 3), you can reduce the case to 2), you will
      win
    4. for n = 4 * 2, you lose
    public class Solution {
        public boolean canWinNim(int n) {
            return (n % 4 != 0);
        }
    }

  • 0
    K

    Completely agree with you, the process of my thinking was the same to you.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.