We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 03740e8 commit 4ad01fdCopy full SHA for 4ad01fd
Tree/662.Maximum-Width-of-Binary-Tree/662.Maximum-Width-of-Binary-Tree.cpp
@@ -21,29 +21,25 @@ class Solution {
21
int len = q.size();
22
ans = max(ans, q.back()->val - q.front()->val + 1);
23
24
- int flag = (len == 1);
+ int base = q.front()->val;
25
26
while (len--)
27
{
28
TreeNode* node = q.front();
29
q.pop_front();
30
-
31
- if (flag==1) node->val = 0;
32
33
if (node->left)
34
35
- node->left->val = node->val*2+1;
+ node->left->val = (node->val-base)*2+1;
36
q.push_back(node->left);
37
}
38
if (node->right)
39
40
- node->right->val = node->val*2+2;
+ node->right->val = (node->val-base)*2+2;
41
q.push_back(node->right);
42
43
44
45
return ans;
46
47
48
49
};
0 commit comments