Solved LeetCode program · 470 of 1,000
#0662 · Maximum Width of Binary Tree
Original English source
Keep a shared values holding 1, 3, 2, 5, 3, and 9. Keep a shared lefts holding 1, 3, -1, -1, -1, and -1. Keep a shared rights holding 2, 4, 5, -1, -1, and -1. The queue is an empty list of whole numbers. The places is an empty list of whole numbers. Place 0 into queue. Place 0 into places. The head is 0. The count is 1. The remaining is 1. The nextcount is 0. The width is 0. The first is 1000000. The last is -1.
Repeat while head is less than count.
The node is item head of queue. The spot is item head of places. Add 1 to head. If spot is less than first, set first to spot. If spot is more than last, set last to spot. If item node of lefts is at least 0, Place item node of lefts into queue, Place spot times 2 plus 1 into places, add 1 to count, add 1 to nextcount. If item node of rights is at least 0, Place item node of rights into queue, Place spot times 2 plus 2 into places, add 1 to count, add 1 to nextcount. Subtract 1 from remaining. The span is last minus first plus 1. The ended is 0. If remaining is 0, set ended to 1. If ended is 1 and span is more than width, set width to span. If ended is 1, set first to 1000000. If ended is 1, set last to -1. If ended is 1, set remaining to nextcount. If ended is 1, set nextcount to 0.
Show width.
Expected stdout
4