Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4bad1d6

Browse files
Create valid_palindrome.js
1 parent a5222f0 commit 4bad1d6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎valid_palindrome.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
var isPalindrome = function(s) {
6+
s = s.replace(/[^A-Za-z0-9]/g, '').toLowerCase();
7+
8+
let left = 0;
9+
let right = s.length - 1;
10+
11+
while(left <= right) {
12+
if (s[left] === s[right]) {
13+
left++;
14+
right--;
15+
} else return false;
16+
}
17+
18+
return true;
19+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /