S2 icon indicating copy to clipboard operation
S2 copied to clipboard

0009. Palindrome Number | LeetCode Cookbook

Open halfrost opened this issue 4 years ago • 7 comments

https://books.halfrost.com/leetcode/ChapterFour/0001~0099/0009.Palindrome-Number/

halfrost avatar Feb 15 '21 03:02 halfrost

follow up 里提到了别用整数转字符串的方式解决,代码里还是转换了下。这里有点疑惑

gaogao1030 avatar Mar 03 '21 20:03 gaogao1030

follow up 里提到了别用整数转字符串的方式解决,代码里还是转换了下。这里有点疑惑

@gaogao1030 我的锅。。我更新啦。把数字转成数组,然后再首尾判断是否相等。你刷新一下看看更新以后的解法。

halfrost avatar Mar 04 '21 06:03 halfrost

follow up 里提到了别用整数转字符串的方式解决,代码里还是转换了下。这里有点疑惑

@gaogao1030 另外我怀疑这个 follow up 是后来加上去的。。我开始做这道题的时候并没有这个要求。

halfrost avatar Mar 04 '21 06:03 halfrost

简单题才能让我有一些存在感。。。。。(滑稽)

hujun2020 avatar Jul 15 '21 11:07 hujun2020

网上看到另外一个解题思路, 这样能少用一些额外的空间 是把数组翻转,和原本的做对比 java版本的 int reminder = 0; int reverse_value = 0; int num = x; if(x < 0){ return false; } while( num!=0 ){

        reminder = num%10; // get the last digit part
        // to restore the value , each time we need to take the 2nd part * 10 since it is reminder followed the 1st part
        reverse_value = reverse_value * 10 + reminder; // the restore the value
        num = num /10;



    }
    return  reverse_value == x;

SteveLiGt avatar Mar 28 '22 20:03 SteveLiGt

解法二中 if x< 10 应该return false吧

shacklesss avatar May 10 '22 01:05 shacklesss

刷完这个题目,我感觉我又行了

Xuzan9396 avatar Dec 01 '22 08:12 Xuzan9396