Categories
不学无术

LeetCode OJ #292. Nim Game

原题地址:https://leetcode.com/problems/nim-game/
思路:
这题目是个找规律的题,号称全OJ最简单….通过找规律可以发现,当n为4的倍数时,无论如何自己都赢不了…然后搞定了
代码:

class Solution {
public:
    bool canWinNim(int n) {
        if(n%4 == 0)
            return false;
        return true;
    }
};

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.