Skip to content

Commit 73b1341

Browse files
committed
valid palindrome solution
1 parent a674237 commit 73b1341

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

β€Žvalid-palindrome/limlimjo.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
var isPalindrome = function(s) {
6+
// 1. λ¬Έμžμ—΄μ„ λ‹€ μ†Œλ¬Έμžλ‘œ λ°”κΎΈκ³ , μ•ŒνŒŒλ²³/숫자 μ•„λ‹Œ κ±° λ‹€ 제거
7+
if (s.length === 1) {
8+
return true;
9+
} else {
10+
let lcLetter = s.toLowerCase().replace(/[^a-z0-9]/g, '');
11+
//console.log(lcLetter);
12+
13+
// 2. λ¬Έμžμ—΄μ΄ μ•žμ—μ„œ μ‹œμž‘ν•  λ•Œμ™€ λ’€μ—μ„œ μ‹œμž‘ν•  λ•Œ κ°™μœΌλ©΄ true, μ•„λ‹ˆλ©΄ false
14+
if(lcLetter) {
15+
for(let i=0; i<Math.floor(lcLetter.length/2); i++) {
16+
if (lcLetter[i] !== lcLetter[lcLetter.length - 1 - i]) return false;
17+
}
18+
return true;
19+
} else {
20+
return true;
21+
}
22+
}
23+
};

0 commit comments

Comments
Β (0)