File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * Definition for a binary tree node.
3+ * function TreeNode(val) {
4+ * this.val = val;
5+ * this.left = this.right = null;
6+ * }
7+ */
8+ /**
9+ * @param {TreeNode } root
10+ * @return {number }
11+ */
12+ var maxDepth = function ( root ) {
13+ if ( root === null ) {
14+ return 0
15+ }
16+ let leftMaxDepth = maxDepth ( root . left )
17+ let rightMaxDepth = maxDepth ( root . right )
18+ return ( leftMaxDepth > rightMaxDepth ? leftMaxDepth : rightMaxDepth ) + 1
19+ } ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number } N
3+ * @param {number[][] } trust
4+ * @return {number }
5+ */
6+ var findJudge = function ( N , trust ) {
7+ if ( N === 1 && trust . length > 0 ) {
8+ return - 1
9+ }
10+ let peopleBeTrusted = new Array ( N )
11+ for ( let i = 0 ; i < peopleBeTrusted . length ; i ++ ) {
12+ peopleBeTrusted [ i ] = 0
13+ }
14+ for ( let i = 0 ; i < trust . length ; i ++ ) {
15+ peopleBeTrusted [ trust [ i ] [ 0 ] - 1 ] = - 1
16+ if ( peopleBeTrusted [ trust [ i ] [ 1 ] - 1 ] !== - 1 ) {
17+ peopleBeTrusted [ trust [ i ] [ 1 ] - 1 ] ++
18+ }
19+ }
20+ let judge = [ ]
21+ for ( let i = 0 ; i < peopleBeTrusted . length ; i ++ ) {
22+ if ( peopleBeTrusted [ i ] === N - 1 ) {
23+ judge . push ( i )
24+ }
25+ }
26+ if ( judge . length === 1 ) {
27+ return judge [ 0 ] + 1
28+ }
29+ return - 1
30+ } ;
You can’t perform that action at this time.
0 commit comments