We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f8ba038 commit 78a5705Copy full SHA for 78a5705
Dynamic Programming/647_Palindromic_Substrings.java
@@ -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