• 19.1.25 [LeetCode9]Palindrome Number


    Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.

    Example 1:

    Input: 121
    Output: true
    

    Example 2:

    Input: -121
    Output: false
    Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
    

    Example 3:

    Input: 10
    Output: false
    Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
    

    Follow up:

    Coud you solve it without converting the integer to a string?

     1 class Solution {
     2 public:
     3     bool isPalindrome(int x) {
     4         if (x < 0)return false;
     5         int y = 0, _x = x;
     6         while (_x) {
     7             y *= 10;
     8             y += _x % 10;
     9             _x /= 10;
    10         }
    11         return (x == y);
    12     }
    13 };
    View Code
    注定失败的战争,也要拼尽全力去打赢它; 就算输,也要输得足够漂亮。
  • 相关阅读:
    存储过程
    事务
    mysql常用函数
    explain相关
    索引相关
    sql基本查询语法
    kubernetes日常记录
    Kubernetes的RBAC权限控制
    kubernetes安装ingress-nginx
    Kubernetes部署nginx-ingress
  • 原文地址:https://www.cnblogs.com/yalphait/p/10318438.html
Copyright © 2020-2023  润新知