File tree Expand file tree Collapse file tree 3 files changed +39
-2
lines changed Expand file tree Collapse file tree 3 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ leetcode 测试
10
10
11
11
##### 包含的内容如下
12
12
13
+ https://leetcode.cn/problems/combination-sum-iii/
14
+
13
15
https://leetcode.cn/problems/range-product-queries-of-powers/
14
16
15
17
https://leetcode.cn/problems/number-of-valid-clock-times/
Original file line number Diff line number Diff line change
1
+ function combinationSum3 ( k : number , n : number ) : number [ ] [ ] {
2
+ if ( n < k || n > 45 ) {
3
+ return [ ] ;
4
+ }
5
+ const nums = Array ( Math . min ( 9 , n - k + 1 ) )
6
+ . fill ( 0 )
7
+ . map ( ( _ , i ) => i + 1 ) ;
8
+ const visited = new Set < number > ( ) ;
9
+ const ans : number [ ] [ ] = [ ] ;
10
+ function dfs ( path : number [ ] , sum : number ) : void {
11
+ // console.log(path, sum);
12
+ if ( sum > n || path . length > k ) return ;
13
+
14
+ if (
15
+ path . length >= 2 && path [ path . length - 1 ] <= path [ path . length - 2 ]
16
+ ) {
17
+ return ;
18
+ }
19
+ if ( path . length === k && sum === n ) {
20
+ ans . push ( [ ...path ] ) ;
21
+ return ;
22
+ }
23
+ for ( const v of nums ) {
24
+ if ( visited . has ( v ) ) continue ;
25
+ path . push ( v ) ;
26
+ visited . add ( v ) ;
27
+ dfs ( path , sum + v ) ;
28
+ path . pop ( ) ;
29
+ visited . delete ( v ) ;
30
+ }
31
+ }
32
+ dfs ( [ ] , 0 ) ;
33
+ return ans ;
34
+ }
35
+ export default combinationSum3 ;
Original file line number Diff line number Diff line change @@ -29,10 +29,10 @@ export default function Fancy(): Fancy {
29
29
r_mult = ( r_mult * multiplicativeInverse ( m , MOD ) ) % MOD ;
30
30
}
31
31
32
- const getIndex = function ( idx : number ) : number {
32
+ function getIndex ( idx : number ) : number {
33
33
if ( idx >= values . length ) return - 1 ;
34
34
return Number ( ( mult * BigInt ( values [ idx ] ) + add ) % MOD ) ;
35
- } ;
35
+ }
36
36
return { getIndex, multAll, addAll, append } ;
37
37
}
38
38
export function multiplicativeInverse ( x : number , mod : bigint ) : bigint {
You can’t perform that action at this time.
0 commit comments