leetcode:数学: Palindrome Number

原创 2016年08月30日 15:10:25

Determine whether an integer is a palindrome. Do this without extra space.


class Solution {
public:
    bool isPalindrome(int x) {
        if (x < 0) return false;
        int bit[10];
        int cnt = 0;
        while (x) {
            bit[cnt++] = x % 10;
            x /= 10;
        }
        for (int i = 0; i < cnt; i++)
            if (bit[i] != bit[cnt - i - 1])
                return false;
        return true;
    }
};
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

【python】【leetcode】【算法题目9—Palindrome Number】

题目原文: Determine whether an integer is a palindrome. Do this without extra space. (不用额外的空间来判断一个整形数字是不...

LeetCode 009. Palindrome Number

Palindrome Number  Total Accepted: 16218 Total Submissions: 55721My Submissions Determine wheth...

Leetcode #9 Palindrome Number

Source: https://leetcode.com/problems/palindrome-number/ 9. Palindrome Number Determine whether an ...
  • mu_jun
  • mu_jun
  • 2016年09月07日 01:45
  • 79

LeetCode : 9. Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space. “回文”是指正读反读都能读通的句子,它是古今中外都...

Leetcode第九题_Palindrome Number

Palindrome Number Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of ...
  • bigevil
  • bigevil
  • 2015年05月19日 00:22
  • 376

[LeetCode] #9 Palindrome Number

好久没有刷题了,现在开始刷LeetCode  GitHub : https://github.com/MummyDing/LeetCode Source : https://leetcode.com/...

Reverse Integer && Palindrome Number-LeetCode

Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 click ...
  • KINGHMY
  • KINGHMY
  • 2017年02月21日 12:01
  • 142

LeetCode-9. Palindrome Number(回文数)

1.题目描述Determine whether an integer is a palindrome. Do this without extra space.Some hints: Could n...

LeetCode || Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space. 判断一个int值是否为回文数。 本题有几点需要...

LeetCode OJ9 Palindrome Number 小结

Palindrome Number题目描述Determine whether an integer is a palindrome. Do this without extra space解题思路我们...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:leetcode:数学: Palindrome Number
举报原因:
原因补充:

(最多只允许输入30个字)