Solved LeetCode program · 107 of 1,000
#0107 · Binary Tree Level Order Traversal II
Original English source
Keep a shared values holding 3, 9, 20, 15, and 7. Keep a shared lefts holding 1, -1, 3, -1, and -1. Keep a shared rights holding 2, -1, 4, -1, and -1.
The queue is an empty list of whole numbers. Place 0 into queue. The head is 0. The count is 1. The remaining is 1. The nextcount is 0. The line is empty text. The rows is an empty list of text.
Repeat while head is less than count.
The node is item head of queue. Add 1 to head. The piece is format whole number item node of values as text. If the length of line is more than 0, Place "," into line. Place piece into line. If item node of lefts is at least 0, Place item node of lefts into queue, add 1 to count, add 1 to nextcount. If item node of rights is at least 0, Place item node of rights into queue, add 1 to count, add 1 to nextcount. Subtract 1 from remaining. If remaining is 0, Place line into rows, set line to empty text, set remaining to nextcount, set nextcount to 0.
The lastrow is the last position of rows.
For every step from 0 to lastrow.
The source is lastrow minus step. Show item source of rows.
Expected stdout
15,7 9,20 3