We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c5ed177 commit 95555e7Copy full SHA for 95555e7
1 file changed
valid-palindrome/nowrobin.js
@@ -0,0 +1,23 @@
1
+/**
2
+ * @param {string} s
3
+ * @return {boolean}
4
+ */
5
+var isPalindrome = function(s) {
6
+ // 1. 소문자로 변환 + 알파벳/숫자만 남기기
7
+ // (공백, 특수문자 제거)
8
+ s = s.toLowerCase().replace(/[^a-z0-9]/g, "");
9
+
10
+ const length = s.length;
11
12
+ // 2. 문자열의 절반만 순회하면서 양쪽 비교
13
+ for (let i = 0; i < length / 2; i++) {
14
+ // 왼쪽(i) vs 오른쪽(length - 1 - i)
15
+ if (s[i] !== s[length - 1 - i]) {
16
+ // 하나라도 다르면 팰린드롬 아님
17
+ return false;
18
+ }
19
20
21
+ // 3. 끝까지 문제 없으면 팰린드롬
22
+ return true;
23
+};
0 commit comments