• LeetCode9——Palindrome Number


      回文数字,简单处理。将数字各位取出,然后用临时变量累加,当累加完成后这个数字等于原来的数字即是回文数。需要注意的是负数不是回文数。

    class Solution
    {
    public:
        bool isPalindrome(int x)
        {
            if(x < 0)
            {
                return false;
            }
            if(x < 10 && x > 0)
            {
                return true;
            }
            int ans = 0;
            int tmp = x;
            while(tmp != 0)
            {
                ans = ans * 10 + tmp % 10;
                tmp /= 10;
            }
            if(ans == x)
            {
                return true;
            }
            return false;
        }
        
    };

      除开回文数字,回文字符该怎么处理。稍安勿躁,肯定会遇到。初步设想是先取得中间,然后从两侧扩展,如果都相同就为回文字符串。核心应该是str[half] = str[length - half + 1];等遇到了再说。

  • 相关阅读:
    数组的地址和vector数组的地址
    字节跳动 测试开发工程师 面经
    最短路径树
    SPFA
    树的直径
    树的重心
    CF1401D Maximum Distributed Tree
    期望简述
    CF723E One-Way Reform
    CF1409E Two Platforms
  • 原文地址:https://www.cnblogs.com/thewaytomakemiracle/p/5027148.html
Copyright © 2020-2023  润新知