Leetcode之PHP版题目解析(9. Palindrome Number)


2019-4-8   

 Leetcode之PHP版题目解析(234. Palindrome Linked List)

a69115900e124c59d2d609b935063a9b.png

,.

,.,.

1

   function isPalindrome($x) {
        if($x<0){
            return false;
        }
        $back=0;$index=$x;
        while($x){
            $back=$back*10+$x%10;
            $x=intval(floor($x/10));
        }
        if($back==$index) {
            return true;
        }else {
            return false;
        }
    }

,0,00(0),,..

   function isPalindrome($x) {
        if($x<0 || $x%10==0 && $x !=0){
            return false;
        }
        $backNumber=0;
        while($x>$backNumber){
            $backNumber=$backNumber*10+$x%10;
            $x =intval(floor($x/10));
        }
        return $x==$backNumber || $x==intval(floor($backNumber /10));
    }

return,,,(),.


Github整理地址:https://github.com/wuqinqiang/leetcode-php


点赞 取消点赞 收藏 取消收藏

<< 上一篇: Leetcode PHP题解--D27 620. Not Boring Movies

>> 下一篇: Leetcode PHP题解--D28 884. Uncommon Words from Two Sentences