Skip to content

Commit b4f068c

Browse files
authored
Merge pull request neetcode-gh#835 from notauserx/Create-647-Palindromic-Substrings.cs
Create 647-Palindromic-Substrings.cs
2 parents 3d7ce26 + 8ffc5e8 commit b4f068c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

csharp/647-Palindromic-Substrings.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public class Solution {
2+
public int CountSubstrings(string s) {
3+
var count = 0;
4+
5+
for(var i = 0; i < s.Length; i++) {
6+
count += getPalindromeCount(s, i, i);
7+
count += getPalindromeCount(s, i, i + 1);
8+
}
9+
10+
return count;
11+
}
12+
13+
public int getPalindromeCount(string s, int l, int r) {
14+
var count = 0;
15+
16+
while(l >=0 && r < s.Length && s[l] == s[r]) {
17+
count++;
18+
l--;
19+
r++;
20+
}
21+
return count;
22+
}
23+
}

0 commit comments

Comments
 (0)