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

吴亲库里 has written 35 articles

情绪只是对自己无能的愤怒

积分:1817 等级:P6 职业:php 城市:杭州

0 条回复

登录后才能进行评论,立即登录?