File tree Expand file tree Collapse file tree 3 files changed +21
-24
lines changed Expand file tree Collapse file tree 3 files changed +21
-24
lines changed Original file line number Diff line number Diff line change 1
- export { default } from "../flood-fill/index.ts"
1
+ export { default } from "../flood-fill/index.ts" ;
Original file line number Diff line number Diff line change 1
- import { TreeNode } from "../mod.ts"
1
+ import { TreeNode } from "../mod.ts" ;
2
2
export default function longestUnivaluePath ( root : TreeNode | null ) : number {
3
-
4
- if ( ! root ) return 0
5
-
6
-
3
+ if ( ! root ) return 0 ;
7
4
8
5
let res = 0 ;
9
-
10
- dfs ( root , s => res = Math . max ( res , s ) ) ;
6
+
7
+ dfs ( root , ( s ) => res = Math . max ( res , s ) ) ;
11
8
return res ;
12
9
}
13
- function dfs ( root : TreeNode | null , out :( s :number ) => void ) {
14
- if ( ! root ) {
15
- return 0 ;
16
- }
17
- const left = dfs ( root . left , out )
18
- const right = dfs ( root . right , out ) ;
19
- let left1 = 0 , right1 = 0 ;
20
- if ( root . left && root . left . val === root . val ) {
21
- left1 = left + 1 ;
22
- }
23
- if ( root . right && root . right . val === root . val ) {
24
- right1 = right + 1 ;
25
- }
26
- out ( left1 + right1 ) ;
27
- return Math . max ( left1 , right1 ) ;
10
+ function dfs ( root : TreeNode | null , out : ( s : number ) => void ) {
11
+ if ( ! root ) {
12
+ return 0 ;
28
13
}
14
+ const left = dfs ( root . left , out ) ;
15
+ const right = dfs ( root . right , out ) ;
16
+ let left1 = 0 , right1 = 0 ;
17
+ if ( root . left && root . left . val === root . val ) {
18
+ left1 = left + 1 ;
19
+ }
20
+ if ( root . right && root . right . val === root . val ) {
21
+ right1 = right + 1 ;
22
+ }
23
+ out ( left1 + right1 ) ;
24
+ return Math . max ( left1 , right1 ) ;
25
+ }
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ export default function subsets(nums: number[]): number[][] {
2
2
const ans : number [ ] [ ] = [ ] ;
3
3
4
4
for ( let i = 0 ; i < 2 ** nums . length ; i ++ ) {
5
- const temp : number [ ] = [ ] ;
5
+ const temp : number [ ] = [ ] ;
6
6
for (
7
7
const [ j , v ] of (
8
8
Array . from ( i . toString ( 2 ) ) . reverse ( ) . entries ( )
You can’t perform that action at this time.
0 commit comments