Skip to content

Commit

Permalink
Merge pull request neetcode-gh#835 from notauserx/Create-647-Palindro…
Browse files Browse the repository at this point in the history
…mic-Substrings.cs

Create 647-Palindromic-Substrings.cs
  • Loading branch information
Ahmad-A0 authored Aug 16, 2022
2 parents 3d7ce26 + 8ffc5e8 commit b4f068c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions csharp/647-Palindromic-Substrings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class Solution {
public int CountSubstrings(string s) {
var count = 0;

for(var i = 0; i < s.Length; i++) {
count += getPalindromeCount(s, i, i);
count += getPalindromeCount(s, i, i + 1);
}

return count;
}

public int getPalindromeCount(string s, int l, int r) {
var count = 0;

while(l >=0 && r < s.Length && s[l] == s[r]) {
count++;
l--;
r++;
}
return count;
}
}

0 comments on commit b4f068c

Please sign in to comment.