Skip to content

Commit b1714d7

Browse files
committed
✨ [9] Palindrome Number
1 parent d3962e9 commit b1714d7

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

9/my_solution.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @param {number} x
3+
* @return {boolean}
4+
*/
5+
const isPalindrome = (x) => {
6+
x = x.toString();
7+
let length = x.length, processedNum = "#";
8+
9+
for (let i = 0; i < x.length; i++) {
10+
processedNum += x[i] + "#";
11+
}
12+
13+
console.log(length);
14+
// console.log(processedNum);
15+
// console.log(processedNum.length);
16+
// console.log(Math.ceil(processedNum.length / 2));
17+
18+
// while ()
19+
for (let i = 0; i < processedNum.length; i++) {
20+
console.log(`${processedNum[i]} ===? ${processedNum[processedNum.length - 1 - i]}`)
21+
if (processedNum[i] !== processedNum[processedNum.length - 1 - i]) return false;
22+
}
23+
24+
return true;
25+
};
26+
27+
let x = isPalindrome(121);
28+
console.log(x);

9/solution.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {number} x
3+
* @return {boolean}
4+
*/
5+
const isPalindrome = (x) => {
6+
x = x.toString();
7+
let processedNum = "#";
8+
9+
for (let i = 0; i < x.length; i++) {
10+
processedNum += x[i] + "#";
11+
}
12+
13+
for (let i = 0; i < processedNum.length; i++) {
14+
if (processedNum[i] !== processedNum[processedNum.length - 1 - i]) return false;
15+
}
16+
17+
return true;
18+
};

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- [4. Median of Two Sorted Arrays](./4/)
1818
- [5. Longest Palindromic Substring](./5/)
1919
- [7. Generate Parentheses](./7/)
20+
- [9. Palindrome Number](./9/)
2021
- [11. Container With Most Water](./11/)
2122
- [15. 3Sum](./15/)
2223
- [19. Remove Nth Node From End of List](./19/)

0 commit comments

Comments
 (0)