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

Sign up
Appearance settings

Commit 60eef74

Browse files
author
asxy
authored
Merge pull request #1 from asxy/asxy-patch-1
Update 0647.回文子串.md
2 parents f848b4f + 0cfe551 commit 60eef74

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎problems/0647.回文子串.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,27 @@ class Solution {
267267
return ans;
268268
}
269269
}
270+
271+
```
272+
273+
动态规划:简洁版
274+
```java
275+
class Solution {
276+
public int countSubstrings(String s) {
277+
boolean[][] dp = new boolean[s.length()][s.length()];
278+
279+
int res = 0;
280+
for (int i = s.length() - 1; i >= 0; i--) {
281+
for (int j = i; j < s.length(); j++) {
282+
if (s.charAt(i) == s.charAt(j) && (j - i <= 1 || dp[i + 1][j - 1])) {
283+
res++;
284+
dp[i][j] = true;
285+
}
286+
}
287+
}
288+
return res;
289+
}
290+
}
270291
```
271292

272293
中心扩散法:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /