9.回文数

时游小于 1 分钟LeetCode

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

上次编辑于:
贡献者: 15327360835
Loading...