Skip to content

Commit 054c27d

Browse files
committed
Palindrome Number(回文数)
1 parent 7a467ea commit 054c27d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
|:---:|:---:|:---:|:---:|
55
|1|[两数之和](https://leetcode-cn.com/problems/two-sum/)|[JavaScript](./algorithms/two-sum.js)|Easy|
66
|2|[两数相加](https://leetcode-cn.com/problems/add-two-numbers/)|[JavaScript](./algorithms/add-two-numbers.js)|Medium|
7+
|9|[回文数](https://leetcode-cn.com/problems/palindrome-number/)|[JavaScript](./algorithms/palindrome-number.js)|Easy|
78

algorithms/palindrome-number.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {number} x
3+
* @return {boolean}
4+
*/
5+
var isPalindrome = function (x) {
6+
if (x < 0) {
7+
return false
8+
}
9+
10+
if (x.toString().split('').reverse().join('') === x.toString()) {
11+
return true
12+
}
13+
14+
return false
15+
};

0 commit comments

Comments
 (0)