File tree Expand file tree Collapse file tree 2 files changed +40
-11
lines changed Expand file tree Collapse file tree 2 files changed +40
-11
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ leetcode 测试
10
10
11
11
### maven
12
12
13
+ https://jitpack.io/#masx200/leetcode-test
14
+
13
15
[ ![ ] ( https://jitpack.io/v/masx200/leetcode-test.svg )] ( https://jitpack.io/#masx200/leetcode-test )
14
16
15
17
To get a Git project into your build:
@@ -19,29 +21,32 @@ Step 1. Add the JitPack repository to your build file
19
21
maven
20
22
21
23
``` xml
22
- <repositories >
23
- <repository >
24
- <id >jitpack.io</id >
25
- <url >https://jitpack.io</url >
26
- </repository >
27
- </repositories >
24
+ <repositories >
25
+ <repository >
26
+ <id >jitpack.io</id >
27
+ <url >https://jitpack.io</url >
28
+ </repository >
29
+ </repositories >
28
30
```
29
31
30
32
Step 2. Add the dependency
31
33
32
34
``` xml
33
- <dependency >
34
- <groupId >com.github.masx200</groupId >
35
- <artifactId >leetcode-test</artifactId >
36
- <version >10.9.2</version >
37
- </dependency >
35
+ <dependency >
36
+ <groupId >com.github.masx200</groupId >
37
+ <artifactId >leetcode-test</artifactId >
38
+ <version >10.9.2</version >
39
+ </dependency >
38
40
```
39
41
40
42
##### 包含的内容如下
41
43
42
44
<details >
45
+
43
46
<summary >展开查看</summary >
44
47
48
+ https://leetcode.cn/problems/er-cha-shu-ran-se-UGC/
49
+
45
50
https://leetcode.cn/problems/combination-sum-iii/
46
51
47
52
https://leetcode.cn/problems/range-product-queries-of-powers/
Original file line number Diff line number Diff line change
1
+ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts" ;
2
+ function maxValue ( root : TreeNode | null , k : number ) {
3
+ return Math . max ( ...dfs ( root , k ) ) ;
4
+ }
5
+ function dfs ( root : TreeNode | null , k : number ) {
6
+ const ans = Array ( k + 1 ) . fill ( 0 ) ;
7
+ if ( ! root ) return ans ;
8
+
9
+ const left = dfs ( root . left , k ) ;
10
+ const right = dfs ( root . right , k ) ;
11
+
12
+ ans . fill ( left [ k ] + right [ k ] ) ;
13
+
14
+ for ( let i = 1 ; i <= k ; i ++ ) {
15
+ let temp = - Infinity ;
16
+ for ( let j = 0 ; j <= i - 1 ; j ++ ) {
17
+ temp = Math . max ( temp , left [ j ] + right [ i - 1 - j ] ) ;
18
+ }
19
+ ans [ i ] = Math . max ( ans [ i ] , temp + root . val ) ;
20
+ }
21
+
22
+ return ans ;
23
+ }
24
+ export default maxValue ;
You can’t perform that action at this time.
0 commit comments