LeetCode 8: Palindrome Number

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

本题是判断一个数是否是回文数。

代码如下:

bool isPalindrome(int x) {
    int max = x;
        int min = 0;
        while(max >0){
            min *= 10;
            min+= max %10;
            max /=10;
        }
        return min==x;

}
时间: 2024-11-05 09:10:07

LeetCode 8: Palindrome Number的相关文章

[LeetCode 题解]:Palindrome Number

前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of c

leetcode笔记:Palindrome Number

一. 题目描述 Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, note the restriction of using extra space. You co

leetcode题目:Palindrome Partitioning 和Palindrome Partitioning II

题目一: Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s = "aab", Return [ ["aa","b"], ["a","a",

LeetCode:Palindrome Number - 回文数

1.题目名称 Palindrome Number(回文数) 2.题目地址 https://leetcode.com/problems/palindrome-number 3.题目内容 英文:Determine whether an integer is a palindrome. Do this without extra space. 中文:确认一个整数是否是回文数 4.解题方法1 将数字翻转后判断与原数字是否相等,可以参考LeetCode第7题(Reverse Integer)的解题思路.J

【LeetCode】009 Palindrome Number

题目:LeetCode 009 Palindrome Number 题意:判断一个整数是否为回文数,不要用额外空间 思路:我不会不用额外空间的方法,需要利用一个长度为20以内的字符串.将整数先写入一个字符串,然后判断首位字符是否相等即可. 代码如下: 1 class Solution { 2 public: 3 bool isPalindrome(int x) { 4 string s = to_string(x); 5 int len = s.size(); 6 for(int i = 0;

LeetCode:Palindrome Number

题目描述: Determine whether an integer is a palindrome. Do this without extra space. 代码: bool Solution::isPalindrome(int x) { int a = x; int b = 0; while(a > 0) { b = b * 10 + a % 10; a = a % 10; } return b == x; }

No.009:Palindrome Number

题目: Determine whether an integer is a palindrome. Do this without extra space. 官方难度: Easy 翻译: 判断一个整数是否为回文结构,不使用额外空间. 思路: 1.回文结构的整数,与之前回文字符串类似,形如1,121,34543,345543的结构. 2.不使用额外空间,表名要从数字而不是字符串的角度来考虑问题. 3.负数不在讨论范围. 4.确定最高位,遍历至maxLevel/2处,检查对称位置即可. 解题中可能遇

LeetCode Problem 9:Palindrome Number回文数

描述:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, note the restriction of using extra space. You could a

LeetCode解题报告--Palindrome Number

题目:回文数字的判断 Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, note the restriction of using extra space. You