leetcode-Problem-2

292.Nim Game

//关键状态
/*
必胜状态: 1<=x<=3
必输状态: 
*/

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

9.回文数

static int x = [](){ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();
class Solution {
public:
    bool isPalindrome(int x) {
        int numSrc = x;
        long long numDst = 0;
        if (x < 0)
        {
            return false;
        }

        while (numSrc)
        {
            numDst = numDst * 10 + numSrc % 10;
            /*
            numSrc % 10 取得个位值
            numDst开始为0,乘10后先进入的逐渐成为高位
            */
            numSrc /= 10;
        }

        return (numDst == x);
    }
};

猜你喜欢

转载自blog.csdn.net/a245293206/article/details/86605881