Anyone can provide non-mathematical solution?

  • 0

    You must use mathematical solution otherwise You May be Out of Memory or Out of Time. Here is my Out Of Time Solution. I have no idea how to fix it. Anyone can help me?

    class Solution {
        bool canWinNim(int n) {
            bool a[3];
            for(int i=0;i<3;i++) a[i] = true;
            for(int i=3;i<n;i++){
                a[i%3] = !(a[(i-1)%3]&&a[(i-2)%3]&&a[(i-3)%3]);
            return a[(n-1)%3];

Log in to reply

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