File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
count-ways-to-build-good-string Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,8 @@ Step 2. Add the dependency
45
45
46
46
<summary >展开查看</summary >
47
47
48
+ https://leetcode.cn/problems/count-ways-to-build-good-string
49
+
48
50
https://leetcode.cn/problems/number-of-distinct-averages
49
51
50
52
https://leetcode.cn/problems/custom-sort-string
Original file line number Diff line number Diff line change
1
+ function countGoodStrings (
2
+ low : number ,
3
+ high : number ,
4
+ zero : number ,
5
+ one : number ,
6
+ ) : number {
7
+ const dp : number [ ] = Array ( high + 1 ) . fill ( 0 ) ;
8
+ dp [ 0 ] = 1 ;
9
+ const mod = 1e9 + 7 ;
10
+ let ans = 0 ;
11
+ for ( let i = 0 ; i <= high ; i ++ ) {
12
+ if ( i >= zero ) dp [ i ] += dp [ i - zero ] ;
13
+ if ( i >= one ) dp [ i ] += dp [ i - one ] ;
14
+ dp [ i ] %= mod ;
15
+ if ( i >= low ) ans = ( ans + dp [ i ] ) % mod ;
16
+ }
17
+ return ans ;
18
+ }
19
+ export default countGoodStrings ;
You can’t perform that action at this time.
0 commit comments