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 ff56ac4

Browse files
String: 125. Valid Palindrome
1 parent 800182e commit ff56ac4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎String/125. Valid Palindrome.js

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

0 commit comments

Comments
(0)

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