Skip to content

Commit a8b8a57

Browse files
committed
9
1 parent d849b02 commit a8b8a57

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

9-palindrome-number.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param {number} x
3+
* @return {boolean}
4+
*/
5+
var isPalindrome = function(x) {
6+
if (x < 0 || (x % 10 == 0 && x != 0)) {
7+
return false;
8+
}
9+
10+
let halfNumber = 0;
11+
while (x > halfNumber) {
12+
halfNumber = halfNumber * 10 + (x % 10);
13+
x = Math.floor(x / 10);
14+
}
15+
16+
return x == halfNumber || x == Math.floor(halfNumber / 10);
17+
};

0 commit comments

Comments
 (0)