Leetcode 算法题 9 回文数
起因, 目的:
数学法。 % 求余数, 拆开组合,组合拆开。
 这个题,翻来覆去,拆开组合, 组合拆开。构建的过程。
题目来源,9 回文数:
https://leetcode.cn/problems/palindrome-number/description/
参考下面这个题解中的第二个写法 (2、数学法(翻转全部数字))
https://leetcode.cn/problems/palindrome-number/solutions/1641138/by-sunny_smile-h468/
代码 1 xxx
def solu(x):
    # 不转为字符串,如何处理?
    if x  < 0:
        return False
    y = 0
    x_copy = x
    while x:
        # y 是从 0 开始的。
        # y 先乘以10, 然后再加上 小数部分, 其中小数部分,是 x 的最后一位。
        # 这个题,翻来覆去,拆开组合, 组合拆开。构建的过程。
        y = y * 10 + x % 10
        # 打印一下, 看看结果。
        print("x: ", x, "y: ", y)
        """
        x:  1221 y:  1
        x:  122 y:  12
        x:  12 y:  122
        x:  1 y:  1221
        """
        x //= 10
    return y == x_copy
print(solu( 1221 ))
老哥留步,支持一下。

