-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0125-Valid-palindrome.cs
More file actions
34 lines (28 loc) · 882 Bytes
/
0125-Valid-palindrome.cs
File metadata and controls
34 lines (28 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Collections.Generic;
using System.Text;
namespace Solution._0125.Valid_palindrome
{
public class _0125_Valid_palindrome
{
public bool IsPalindrome(string s)
{
if (string.IsNullOrWhiteSpace(s)) return true;
int left = 0;
int right = s.Length - 1;
s = s.ToLower();
while (left < right)
{
while ((left < right) && (s[left] < 'a' || s[left] > 'z') && (s[left] < '0' || s[left] > '9'))
left++;
while ((left < right) && (s[right] < 'a' || s[right] > 'z') && (s[right] < '0' || s[right] > '9'))
right--;
if (s[left] != s[right])
return false;
left++;
right--;
}
return true;
}
}
}