题解 | #牛的回文编号#

牛的回文编号

https://www.nowcoder.com/practice/f864e31a772240f1b4310fbdc27fad48

知识点

字符串

解题思路

将x转成字符串放进StringBuilder中,将字符串反正与最初的字符串比对,如果相同则表示是回文串。

Java题解

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param x int整型 
     * @return bool布尔型
     */
    public boolean isPalindrome (int x) {
        // write code here
        String s = String.valueOf(x);
        StringBuilder sb1 = new StringBuilder(s);
        sb1.reverse();
        return sb1.toString().equals(s);
    }
}

全部评论

相关推荐

醉蟀:你是我今年见过的最美牛客女孩
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务