zoukankan      html  css  js  c++  java
  • 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
    注定失败的战争,也要拼尽全力去打赢它; 就算输,也要输得足够漂亮。
  • 相关阅读:
    UVa10036
    矩阵链乘法(动态规划)
    Codeforces 230A
    iOS 界面开发
    iOS 自动布局
    iOS 自动布局过程
    iOS 界面布局,设置约束
    iOS + UIWebView 实践
    iOS 参考 网络书籍
    iOS 框架 Nimbus
  • 原文地址:https://www.cnblogs.com/yalphait/p/10318438.html
Copyright © 2011-2022 走看看