题解 | #牛的回文编号#
牛的回文编号
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);
}
}
查看7道真题和解析
360集团公司氛围 358人发布