9.回文数
小于 1 分钟
9.回文数
/*
* @lc app=leetcode.cn id=9 lang=typescript
*
* [9] 回文数
*/
// @lc code=start
// 转数组后,前后对比
// function isPalindrome(x: number): boolean {
// let arr: string[] = String(x).split("");
// let res: boolean[] = [];
// arr.map((el, index) => {
// if (el !== arr[arr.length - index - 1]) {
// res.push(false);
// } else {
// res.push(true);
// }
// });
// return !res.includes(false);
// }
function isPalindrome(x:number):boolean{
return String(x) === x.toString().split("").reverse().join("")
}
// @lc code=end
Loading...
