Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b2fe516

Browse files
authored
Added solution for 125 Valid Palindrome
1 parent df90bd6 commit b2fe516

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

csharp/125-Valid-Palindrome.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
namespace AlgoPractice
3+
{
4+
public class Solution
5+
{
6+
public bool IsPalindrome(string s)
7+
{
8+
var left = 0;
9+
var right = s.Length - 1;
10+
11+
while(left < right)
12+
{
13+
while (left < right && !char.IsLetterOrDigit(s[left])) left++;
14+
while (left < right && !char.IsLetterOrDigit(s[right])) right--;
15+
16+
if (char.ToLower(s[left]) != char.ToLower(s[right]))
17+
{
18+
return false;
19+
}
20+
else
21+
{
22+
left++;
23+
right--;
24+
}
25+
26+
}
27+
return true;
28+
}
29+
}
30+
}
31+

0 commit comments

Comments
 (0)