Skip to content

Commit 482ef63

Browse files
committedMar 31, 2021
Create README - LeetHub
1 parent 635c34b commit 482ef63

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
 
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<h2>662. Maximum Width of Binary Tree</h2><h3>Medium</h3><hr><div><p>Given a binary tree, write a function to get the maximum width of the given tree. The maximum width of a tree is the maximum width among all levels.</p>
2+
3+
<p>The width of one level is defined as the length between the end-nodes (the leftmost and right most non-null nodes in the level, where the <code>null</code> nodes between the end-nodes are also counted into the length calculation.</p>
4+
5+
<p>It is <strong>guaranteed</strong> that the answer will in the range of 32-bit signed integer.</p>
6+
7+
<p><b>Example 1:</b></p>
8+
9+
<pre><b>Input:</b>
10+
11+
1
12+
/ \
13+
3 2
14+
/ \ \
15+
5 3 9
16+
17+
<b>Output:</b> 4
18+
<b>Explanation:</b> The maximum width existing in the third level with the length 4 (5,3,null,9).
19+
</pre>
20+
21+
<p><b>Example 2:</b></p>
22+
23+
<pre><b>Input:</b>
24+
25+
1
26+
/
27+
3
28+
/ \
29+
5 3
30+
31+
<b>Output:</b> 2
32+
<b>Explanation:</b> The maximum width existing in the third level with the length 2 (5,3).
33+
</pre>
34+
35+
<p><b>Example 3:</b></p>
36+
37+
<pre><b>Input:</b>
38+
39+
1
40+
/ \
41+
3 2
42+
/
43+
5
44+
45+
<b>Output:</b> 2
46+
<b>Explanation:</b> The maximum width existing in the second level with the length 2 (3,2).
47+
</pre>
48+
49+
<p><b>Example 4:</b></p>
50+
51+
<pre><b>Input:</b>
52+
53+
1
54+
/ \
55+
3 2
56+
/ \
57+
5 9
58+
/ \
59+
6 7
60+
<b>Output:</b> 8
61+
<b>Explanation:</b>The maximum width existing in the fourth level with the length 8 (6,null,null,null,null,null,null,7).
62+
</pre>
63+
64+
<p>&nbsp;</p>
65+
<p><strong>Constraints:</strong></p>
66+
67+
<ul>
68+
<li>The&nbsp;given binary tree will have between&nbsp;<code>1</code>&nbsp;and&nbsp;<code>3000</code>&nbsp;nodes.</li>
69+
</ul>
70+
</div>

0 commit comments

Comments
 (0)
Please sign in to comment.