Skip to content

Commit

Permalink
Merge pull request youngyangyang04#2042 from asxy/asxy-patch-1
Browse files Browse the repository at this point in the history
Update 0647.回文子串.md
  • Loading branch information
youngyangyang04 authored May 1, 2023
2 parents 66ad8c1 + 0cfe551 commit ccf4089
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions problems/0647.回文子串.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,27 @@ class Solution {
return ans;
}
}
```

动态规划:简洁版
```java
class Solution {
public int countSubstrings(String s) {
boolean[][] dp = new boolean[s.length()][s.length()];

int res = 0;
for (int i = s.length() - 1; i >= 0; i--) {
for (int j = i; j < s.length(); j++) {
if (s.charAt(i) == s.charAt(j) && (j - i <= 1 || dp[i + 1][j - 1])) {
res++;
dp[i][j] = true;
}
}
}
return res;
}
}
```

中心扩散法:
Expand Down

0 comments on commit ccf4089

Please sign in to comment.