Skip to content

Commit c17d7bc

Browse files
committed
Add 125
1 parent 13f114d commit c17d7bc

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Other/125_valid_palindrome.cs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Text.RegularExpressions;
2+
3+
public class Solution {
4+
public bool IsPalindrome(string s) {
5+
// string output = Regex.Replace(s.ToLower(), @"[^a-zA-Z0-9]", "");
6+
s = s.ToLower();
7+
int leftIndex = 0;
8+
int rightIndex = s.Length - 1;
9+
10+
while(leftIndex < s.Length) {
11+
if (!Char.IsLetterOrDigit(s[leftIndex])){
12+
leftIndex++;
13+
continue;
14+
}
15+
16+
if (!Char.IsLetterOrDigit(s[rightIndex])){
17+
rightIndex--;
18+
continue;
19+
}
20+
21+
if(s[leftIndex] != s[rightIndex]){
22+
return false;
23+
}
24+
leftIndex++;
25+
rightIndex--;
26+
}
27+
return true;
28+
}
29+
}

0 commit comments

Comments
 (0)