Example: binary tree: [3,9,20, null, null, 15, 7],
3
/\
September 20
/\
15 July
Returns to its level traversal results:
[3],
[9],
[15, 7]
]
Now my code output below, what's the problem????????????????
Input,9,20,1,2,3,15 [3]
My code output [[3], [20], [15]]
The expected output should be the result of [[3], [9], [1,2,3,15]]
/* ** Definition for a binary tree node.
* struct TreeNode {
* int val.
* TreeNode * left;
* TreeNode * right;
* TreeNode (int x) : val (x), left (NULL), right (NULL) {}
*};
*/
The class Solution {
Public:
VectorLevelOrder (root TreeNode *) {
VectorRe;
If (root==NULL)
Return re;
DequeInt size=1;
While (size)
{
VectorHang;
TreeNode * temp=the queue in front ();
Hang the push_back (temp - & gt; Val);
If (temp - & gt; Left!=NULL)
The queue. The push_back (temp - & gt; Left);
If (temp - & gt; Right!=NULL)
The queue. The push_back (temp - & gt; Right);
Queue. Pop_front ();
Size -;
If (size==0)
{
Size=queue. The size ();
Re. The push_back (hang);
}
}
Return re;
}
};