-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpalindrome.js
More file actions
48 lines (38 loc) · 748 Bytes
/
palindrome.js
File metadata and controls
48 lines (38 loc) · 748 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* @param {number} x
* @return {boolean}
*/
var isPalindrome = function(x) {
let second = 0;
let i = 1;
let len = 0;
let z = x;
if (x < 0)
return false;
while(true) {
let temp = Math.pow(10, i);
if(x / temp < 1) {
len = i - 1;
break;
}
i++;
}
if (len === 0)
return true;
// i = 1;
let j = 0;
let temp = z;
while(j <= len) {
temp = z % 10;
console.log(z)
second += (temp * Math.pow(10, i - 1));
console.log(second)
z = Math.trunc(z / 10);
temp = z;
console.log(z)
console.log("---\n")
j++;
i--;
}
return x === second;
};