Skip to content

Commit fc2ad73

Browse files
committed
solve palindromic substrings
1 parent 706f910 commit fc2ad73

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int countSubstrings(String s) {
3+
int count = 0;
4+
5+
for (int i = 0; i < 2 * s.length() - 1; i++) {
6+
int left = i / 2;
7+
int right = left + i % 2;
8+
9+
while (left >= 0 && right < s.length() && s.charAt(left) == s.charAt(right)) {
10+
count++;
11+
left--;
12+
right++;
13+
}
14+
}
15+
16+
return count;
17+
}
18+
}
19+

0 commit comments

Comments
 (0)