Solved LeetCode program · 196 of 1,000
#0226 · Invert Binary Tree
Original English source
Keep a shared values holding 4, 2, 7, 1, 3, 6, and 9. Keep a shared lefts holding 1, 3, 5, -1, -1, -1, and -1. Keep a shared rights holding 2, 4, 6, -1, -1, -1, and -1.
To mirror from node (a whole number). If node is less than 0, return. The saved is item node of lefts. Set item node of lefts to item node of rights. Set item node of rights to saved. Mirror from item node of lefts. Mirror from item node of rights.
Mirror from 0. The queue is an empty list of whole numbers. Place 0 into queue. The head is 0. The count is 1.
Repeat while head is less than count.
The node is item head of queue. Add 1 to head. Show item node of values. The left is item node of lefts. The right is item node of rights. If left is at least 0, Place left into queue, add 1 to count. If right is at least 0, Place right into queue, add 1 to count.
Expected stdout
4 7 2 9 6 3 1