Skip to content

Commit ab3ffd5

Browse files
Create palindrome.js
1 parent 05c2163 commit ab3ffd5

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

palindrome.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @param {number} x
3+
* @return {boolean}
4+
*/
5+
var isPalindrome = function(x) {
6+
let second = 0;
7+
let i = 1;
8+
let len = 0;
9+
let z = x;
10+
11+
if (x < 0)
12+
return false;
13+
14+
while(true) {
15+
let temp = Math.pow(10, i);
16+
17+
if(x / temp < 1) {
18+
len = i - 1;
19+
break;
20+
}
21+
22+
i++;
23+
}
24+
25+
if (len === 0)
26+
return true;
27+
28+
// i = 1;
29+
30+
let j = 0;
31+
let temp = z;
32+
while(j <= len) {
33+
temp = z % 10;
34+
console.log(z)
35+
36+
second += (temp * Math.pow(10, i - 1));
37+
console.log(second)
38+
39+
z = Math.trunc(z / 10);
40+
temp = z;
41+
console.log(z)
42+
console.log("---\n")
43+
j++;
44+
i--;
45+
}
46+
47+
return x === second;
48+
};

0 commit comments

Comments
 (0)