Skip to content

Commit fdeed29

Browse files
committed
feat: 문제풀이 추가
1 parent 5d93b0f commit fdeed29

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

valid-palindrome/hwanmini.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// 시간복잡도: O(n)
2+
// 공간복잡도: O(n)
3+
4+
/**
5+
* @param {string} s
6+
* @return {boolean}
7+
*/
8+
var isPalindrome = function(s) {
9+
const strs = s.replace(/[^a-z0-9]/gi, '').toLowerCase();
10+
11+
let leftIdx = 0;
12+
let rightIdx = strs.length - 1
13+
14+
while (leftIdx <= rightIdx) {
15+
if (strs[leftIdx] !== strs[rightIdx]) return false
16+
17+
leftIdx++
18+
rightIdx--
19+
}
20+
21+
22+
return true
23+
};
24+
25+
const s = "A man, a plan, a canal: Panama"
26+
27+
28+
console.log(isPalindrome(s))
29+

0 commit comments

Comments
 (0)