Skip to content

Commit be13a43

Browse files
committed
Runtime: 1 ms (Top 70.91%) | Memory: 41.7 MB (Top 98.42%)
1 parent 02f8da7 commit be13a43

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1+
// Runtime: 1 ms (Top 70.91%) | Memory: 41.7 MB (Top 98.42%)
12
/**
23
* Definition for a binary tree node.
34
* public class TreeNode {
4-
* int val;
5-
* TreeNode left;
6-
* TreeNode right;
7-
* TreeNode() {}
8-
* TreeNode(int val) { this.val = val; }
9-
* TreeNode(int val, TreeNode left, TreeNode right) {
10-
* this.val = val;
11-
* this.left = left;
12-
* this.right = right;
13-
* }
5+
* int val;
6+
* TreeNode left;
7+
* TreeNode right;
8+
* TreeNode() {}
9+
* TreeNode(int val) { this.val = val; }
10+
* TreeNode(int val, TreeNode left, TreeNode right) {
11+
* this.val = val;
12+
* this.left = left;
13+
* this.right = right;
14+
* }
1415
* }
1516
*/
1617
class Solution {
1718
public int maxAncestorDiff(TreeNode root) {
18-
19+
1920
if (root == null) return 0;
20-
21+
2122
return find(root, Integer.MAX_VALUE, Integer.MIN_VALUE);
2223
}
23-
24+
2425
public int find(TreeNode root, int min, int max) {
2526
if (root == null) return Math.abs(max-min);
26-
27+
2728
min = Math.min(min, root.val);
2829
max = Math.max(max, root.val);
29-
30+
3031
return Math.max(find(root.left, min, max), find(root.right, min, max));
3132
}
32-
33-
34-
}
33+
34+
}

0 commit comments

Comments
 (0)