Skip to content

Commit 0b766fd

Browse files
committed
Create README - LeetHub
1 parent 5363df2 commit 0b766fd

File tree

1 file changed

+30
-0
lines changed
  • 1026-maximum-difference-between-node-and-ancestor

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<h2><a href="https://leetcode.com/problems/maximum-difference-between-node-and-ancestor/">1026. Maximum Difference Between Node and Ancestor</a></h2><h3>Medium</h3><hr><div><p>Given the <code>root</code> of a binary tree, find the maximum value <code>v</code> for which there exist <strong>different</strong> nodes <code>a</code> and <code>b</code> where <code>v = |a.val - b.val|</code> and <code>a</code> is an ancestor of <code>b</code>.</p>
2+
3+
<p>A node <code>a</code> is an ancestor of <code>b</code> if either: any child of <code>a</code> is equal to <code>b</code>&nbsp;or any child of <code>a</code> is an ancestor of <code>b</code>.</p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong class="example">Example 1:</strong></p>
7+
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/09/tmp-tree.jpg" style="width: 400px; height: 390px;">
8+
<pre><strong>Input:</strong> root = [8,3,10,1,6,null,14,null,null,4,7,13]
9+
<strong>Output:</strong> 7
10+
<strong>Explanation: </strong>We have various ancestor-node differences, some of which are given below :
11+
|8 - 3| = 5
12+
|3 - 7| = 4
13+
|8 - 1| = 7
14+
|10 - 13| = 3
15+
Among all possible differences, the maximum value of 7 is obtained by |8 - 1| = 7.</pre>
16+
17+
<p><strong class="example">Example 2:</strong></p>
18+
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/09/tmp-tree-1.jpg" style="width: 250px; height: 349px;">
19+
<pre><strong>Input:</strong> root = [1,null,2,null,0,3]
20+
<strong>Output:</strong> 3
21+
</pre>
22+
23+
<p>&nbsp;</p>
24+
<p><strong>Constraints:</strong></p>
25+
26+
<ul>
27+
<li>The number of nodes in the tree is in the range <code>[2, 5000]</code>.</li>
28+
<li><code>0 &lt;= Node.val &lt;= 10<sup>5</sup></code></li>
29+
</ul>
30+
</div>

0 commit comments

Comments
 (0)