File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
src/main/ts/g0401_0500/s0437_path_sum_iii Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -6,20 +6,22 @@ function pathSum(root: TreeNode | null, targetSum: number): number {
6
6
let map = new Map < number , number > ( )
7
7
8
8
function dfs ( node : TreeNode | null , currentSum : number ) : void {
9
- if ( ! node ) return
10
-
9
+ if ( ! node ) {
10
+ return
11
+ }
11
12
currentSum += node . val
12
- if ( currentSum === targetSum ) count ++
13
-
13
+ if ( currentSum === targetSum ) {
14
+ count ++
15
+ }
14
16
count += map . get ( currentSum - targetSum ) ?? 0
15
-
16
17
map . set ( currentSum , map . get ( currentSum ) + 1 || 1 )
17
18
dfs ( node ?. left , currentSum )
18
19
dfs ( node ?. right , currentSum )
19
-
20
20
//remove from hashmap
21
21
map . set ( currentSum , map . get ( currentSum ) - 1 )
22
- if ( map . get ( currentSum ) === 0 ) map . delete ( currentSum )
22
+ if ( map . get ( currentSum ) === 0 ) {
23
+ map . delete ( currentSum )
24
+ }
23
25
}
24
26
25
27
dfs ( root , 0 )
You can’t perform that action at this time.
0 commit comments