forked from LeetCode-in-Net/LeetCode-in-Net
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
29 lines (26 loc) · 761 Bytes
/
Solution.cs
File metadata and controls
29 lines (26 loc) · 761 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
namespace LeetCodeNet.G0601_0700.S0647_palindromic_substrings {
// #Medium #String #Dynamic_Programming #Big_O_Time_O(n^2)_Space_O(n)
// #2025_06_16_Time_10_ms_(72.48%)_Space_38.84_MB_(83.72%)
public class Solution {
private void Expand(char[] a, int l, int r, int[] res) {
while (l >= 0 && r < a.Length) {
if (a[l] != a[r]) {
return;
} else {
res[0]++;
l--;
r++;
}
}
}
public int CountSubstrings(string s) {
char[] a = s.ToCharArray();
int[] res = {0};
for (int i = 0; i < a.Length; i++) {
Expand(a, i, i, res);
Expand(a, i, i + 1, res);
}
return res[0];
}
}
}