- 题目描述:
- 题目链接:
-视频讲解链接B站视频讲解
- 复杂度分析:
- 代码:
c++版本:
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
* 判断x是不是好数
* @param x int整型 待判断的数
* @return bool布尔型
*/
bool judge(int x) {
// write code here
int n = 0;//代表数字长度
int a[10];//用来保存每一位数字
while(x){
a[n] = x % 10;
n ++;
x /= 10;
}
return a[0] == a[n - 1]? 1:0;
}
};
Java版本:
import java.util.*;
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
* 判断x是不是好数
* @param x int整型 待判断的数
* @return bool布尔型
*/
public boolean judge (int x) {
// write code here
int n = 0;//代表数字长度
int []a = new int[10];//用来保存每一位数字
while(x > 0){
a[n] = x % 10;
n ++;
x /= 10;
}
return a[0] == a[n - 1]? true:false;
}
}Python版本:
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
# 判断x是不是好数
# @param x int整型 待判断的数
# @return bool布尔型
#
class Solution:
def judge(self , x ):
# write code here
n = 0#代表数字长度
a = [0] * 10#用来保存每一位数字
while x > 0:
a[n] = x % 10
n += 1
x = x // 10
return (True if a[0] == a[n-1] else False) JavaScript版本:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
* 判断x是不是好数
* @param x int整型 待判断的数
* @return bool布尔型
*/
function judge( x ) {
// write code here
let n = 0;//代表数字长度
var a = new Array();//用来保存每一位数字
while(x > 0){
a[n] = x % 10;
n ++;
x = parseInt(x/10);
}
return a[0] == a[n - 1]? true:false;
}
module.exports = {
judge : judge
};
京公网安备 11010502036488号