File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
maximum-number-of-non-overlapping-palindrome-substrings Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -131,6 +131,8 @@ https://leetcode.cn/problems/magical-string/
131
131
132
132
https://leetcode.cn/problems/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof/
133
133
134
+ https://leetcode.cn/problems/maximum-number-of-non-overlapping-palindrome-substrings
135
+
134
136
https://leetcode.cn/problems/nge-tou-zi-de-dian-shu-lcof
135
137
136
138
https://leetcode.cn/problems/count-of-matches-in-tournament/
Original file line number Diff line number Diff line change
1
+ export default function maxPalindromes ( s : string , k : number ) : number {
2
+ const n = s . length ;
3
+ const f : number [ ] = Array ( n + 1 ) . fill ( 0 ) ;
4
+ for ( let i = 0 ; i < 2 * n - 1 ; ++ i ) {
5
+ let l = Math . floor ( i / 2 ) ,
6
+ r = l + ( i % 2 ) ; // 中心扩展法
7
+ f [ l + 1 ] = Math . max ( f [ l + 1 ] , f [ l ] ) ;
8
+ for ( ; l >= 0 && r < n && s [ l ] == s [ r ] ; -- l , ++ r ) {
9
+ if ( r - l + 1 >= k ) f [ r + 1 ] = Math . max ( f [ r + 1 ] , f [ l ] + 1 ) ;
10
+ }
11
+ }
12
+ return f [ n ] ;
13
+ }
You can’t perform that action at this time.
0 commit comments