Solved LeetCode program · 957 of 1,000
#1325 · Delete Leaves With a Given Value
Original English source
Keep a shared values as an empty list of whole numbers. Keep a shared lefts as an empty list of whole numbers. Keep a shared rights as an empty list of whole numbers. Keep a shared newleft as an empty list of whole numbers. Keep a shared newright as an empty list of whole numbers. Keep a shared resultnode of 0. Keep a shared queue as an empty list of whole numbers. Keep a shared order as an empty list of text. Keep a shared tail of 0. Keep a shared target of 2. Place 1 into values. Place 2 into values. Place 3 into values. Place 2 into values. Place 2 into values. Place 3 into values. Place 4 into values. Place 1 into lefts. Place 3 into lefts. Place 5 into lefts. Place -1 into lefts. Place -1 into lefts. Place -1 into lefts. Place -1 into lefts. Place 2 into rights. Place 4 into rights. Place 6 into rights. Place -1 into rights. Place -1 into rights. Place -1 into rights. Place -1 into rights. For every node from 0 to 6, Place 0 into newleft. For every node from 0 to 6, Place 0 into newright. For every cell from 0 to 15, Place 0 into queue.
To prune from node (a whole number). If node is less than 0, set resultnode to -1, return. The left is item node of lefts. The right is item node of rights. Prune from left. The freshleft is resultnode. Prune from right. The freshright is resultnode. Set item node of newleft to freshleft. Set item node of newright to freshright. The piece is item node of values. If freshleft is less than 0 and freshright is less than 0 and piece is target, set resultnode to -1, otherwise set resultnode to node.
To spread from node (a whole number). The left is item node of newleft. The right is item node of newright. Set item tail of queue to left. Add 1 to tail. Set item tail of queue to right. Add 1 to tail.
To handlelive from node (a whole number). The piece is item node of values. The written is format whole number piece as text. Place written into order. Spread from node.
To handle from node (a whole number). If node is less than 0, Place "-1" into order, otherwise Handlelive from node.
Prune from 0. The root is resultnode. The head is 0. Set tail to 1. Set item 0 of queue to root.
Repeat while head is less than tail.
The node is item head of queue. Add 1 to head. Handle from node.
The mark is "-1". The cut is the last position of order.
Repeat while cut is at least 0.
The symbol is item cut of order. If symbol matches mark, set cut to cut minus 1, otherwise stop.
For every spot from 0 to cut, Show item spot of order.
Expected stdout
1 -1 3 3 4