Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 660b8d3

Browse files
committed
add valid palindrome draft
1 parent d4ea871 commit 660b8d3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

101-200/125-valid-palindrome.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Author :- Rishabh Jain <contact@rishabh1403.com>
3+
Solution for :- https://leetcode.com/problems/valid-palindrome/
4+
blog for this code :- https://rishabh1403.com/posts/coding/leetcode/2020/03/leetcode-search-insert-position
5+
youtube video :- https://youtu.be/l2XPvyTlC6c
6+
*/
7+
8+
var isPalindrome = function (s) {
9+
if (s.length === 0) return true;
10+
11+
s = s.toLowerCase();
12+
let i = 0, j = s.length - 1;
13+
while (i < j) {
14+
if ((s[i] < 'a' || s[i] > 'z') && (s[i] < '0' || s[i] > '9')) {
15+
i++;
16+
continue;
17+
}
18+
if ((s[j] < 'a' || s[j] > 'z') && (s[j] < '0' || s[j] > '9')) {
19+
j--;
20+
continue;
21+
}
22+
if (s[i] !== s[j]) {
23+
return false;
24+
}
25+
i++;
26+
j--;
27+
}
28+
29+
return true;
30+
};

0 commit comments

Comments
 (0)