Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 78a5705

Browse filesBrowse files
Sean PrashadSean Prashad
authored andcommitted
Add 647_Palindromic_Substrings.java
1 parent f8ba038 commit 78a5705
Copy full SHA for 78a5705

File tree

Expand file treeCollapse file tree

1 file changed

+22
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+22
-0
lines changed
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public int countSubstrings(String s) {
3+
if (s == null || s.length() == 0) {
4+
return 0;
5+
}
6+
7+
int result = 0, n = s.length();
8+
boolean[][] dp = new boolean[n][n];
9+
10+
for (int i = n - 1; i >= 0; i--) {
11+
for (int j = i; j < n; j++) {
12+
dp[i][j] = s.charAt(i) == s.charAt(j) && (j - i < 2 || dp[i + 1][j - 1]);
13+
14+
if (dp[i][j]) {
15+
++result;
16+
}
17+
}
18+
}
19+
20+
return result;
21+
}
22+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.