Skip to content

Commit d6c48ae

Browse files
palindrom problem solved
1 parent 1c55de3 commit d6c48ae

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"cSpell.words": ["Palindrom"]
3+
}

9-palindrom.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//-121 is palindrom or not?
2+
3+
function isPalindrom(num) {
4+
let temp = num;
5+
let rev = 0;
6+
while (temp > 0) {
7+
let lastDigit = temp % 10;
8+
rev = rev * 10 + lastDigit;
9+
temp = Math.floor(temp / 10);
10+
}
11+
return rev === num;
12+
}
13+
14+
isPalindrom(-121)

0 commit comments

Comments
 (0)