Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e28e155

Browse files
committed
upd: 回文数
1 parent f13af0d commit e28e155

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ LeetCode JavaScript Solution
1515
| Longest Palindromic Substring | Medium | 2018年01月19日 |
1616
| Reverse Integer | Easy | 2018年01月19日 |
1717
| Regular Expression Matching | Hard | 2018年03月09日 |
18+
| Palindrome Number | Easy | 2018年03月16日 |

‎src/palindromeNumber.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {number} x
3+
* @return {boolean}
4+
*/
5+
var isPalindrome = function(x) {
6+
if (x < 0) return false;
7+
let temp = Math.abs(x).toString();
8+
let i = 0, j = temp.length - 1;
9+
let ret = true;
10+
while (i < j) {
11+
if (temp[i] === temp[j]) {
12+
++i;
13+
--j;
14+
} else {
15+
ret = false;
16+
break;
17+
}
18+
}
19+
return ret;
20+
};
21+
22+
isPalindrome(-2147447412);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /