题解 | #回文数字#

回文数字

http://www.nowcoder.com/practice/35b8166c135448c5a5ba2cff8d430c32

//直接用函数转换成字符,双指针判断

public:
    /**
     * 
     * @param x int整型 
     * @return bool布尔型
     */
    bool isPalindrome(int x) {
        // write code here
        string s=to_string(x);
        int l=0;
        int r=s.length()-1;
        while(l<r)
        {
            if(s[l]!=s[r])return false;
            l++;
            r--;
        }
        return true;
    }
};
全部评论

相关推荐

评论
2
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务