Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1946 from thuanle123/680-valid-palindr…
Browse files Browse the repository at this point in the history
…ome-ii

create 680. Valid Palindrome II c#
  • Loading branch information
tahsintunan authored Jan 8, 2023
2 parents 3352f06 + da6e869 commit 66ac5a3
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions csharp/0680-valid-palindrome-ii.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
public class Solution
{
public bool ValidPalindrome(string s)
{
int leftPointer = 0;
int rightPointer = s.Length - 1;
while (leftPointer < rightPointer)
{
if (s[leftPointer] != s[rightPointer])
{
return IsPalindrome(s, leftPointer + 1, rightPointer) || IsPalindrome(s, leftPointer, rightPointer - 1);
}
leftPointer++;
rightPointer--;
}
return true;
}
public bool IsPalindrome(String s, int leftPointer, int rightPointer)
{
while (leftPointer < rightPointer)
{
if (s[leftPointer] != s[rightPointer])
{
return false;
}
leftPointer++;
rightPointer--;
}
return true;
}
}

0 comments on commit 66ac5a3

Please sign in to comment.