forked from lazzzis/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
31 lines (30 loc) · 677 Bytes
/
Copy pathmain.js
File metadata and controls
31 lines (30 loc) · 677 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* @param {number} x
* @return {boolean}
*/
var isPalindrome = function (x) {
if (x < 0) {
return false
}
let start = Math.pow(10, Math.floor(Math.log10(x)))
let end = 1
while (start > end) {
if (Math.floor(x / start) % 10 !== Math.floor(x / end) % 10) {
return false
}
start /= 10
end *= 10
}
return true
}
if (process.env.LZS) { // local test
const assert = require('assert')
assert(isPalindrome(101))
assert(isPalindrome(10101))
assert(isPalindrome(1221))
assert(isPalindrome(1223) === false)
assert(isPalindrome(-1221) === false)
assert(isPalindrome(1))
assert(isPalindrome(0))
assert(isPalindrome(29992))
}