Solved LeetCode program · 823 of 1,000
#1080 · Insufficient Nodes in Root to Leaf Paths
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 gone as an empty list of whole numbers. Keep a shared cap of 0. Keep a shared result of 0. Set cap to 22. Place 5 into values. Place 4 into values. Place 8 into values. Place 11 into values. Place 0 into values. Place 17 into values. Place 4 into values. Place 7 into values. Place 1 into values. Place 0 into values. Place 0 into values. Place 5 into values. Place 3 into values. Place 1 into lefts. Place 3 into lefts. Place 5 into lefts. Place 7 into lefts. Place -1 into lefts. Place -1 into lefts. Place 11 into lefts. Place -1 into lefts. Place -1 into lefts. Place -1 into lefts. Place -1 into lefts. Place -1 into lefts. Place -1 into lefts. Place 2 into rights. Place -1 into rights. Place 6 into rights. Place 8 into rights. Place -1 into rights. Place -1 into rights. Place 12 into rights. Place -1 into rights. Place -1 into rights. Place -1 into rights. Place -1 into rights. Place -1 into rights. Place -1 into rights.
For every spot from 0 to 12.
Place 0 into gone.
To prune from node (a whole number) with total (a whole number). If node is less than 0, set result to -1000000000, return. The value is item node of values. The here is total plus value. The left is item node of lefts. The right is item node of rights. The leftbest is 0. The rightbest is 0. If left is at least 0, Prune from left with here, set leftbest to result. If right is at least 0, Prune from right with here, set rightbest to result. The best is -1000000000. If left is less than 0 and right is less than 0, set best to here. If left is at least 0 and leftbest is more than best, set best to leftbest. If right is at least 0 and rightbest is more than best, set best to rightbest. If best is less than cap, set item node of gone to 1. If best is at least cap, set item node of gone to 0. If left is at least 0 and item left of gone is 1, set item node of lefts to -1. If right is at least 0 and item right of gone is 1, set item node of rights to -1. Set result to best.
Prune from 0 with 0. The queue is an empty list of whole numbers. Place 0 into queue. The head is 0. The count is 1. The pieces 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 empty text. If node is at least 0, set piece to format whole number item node of values as text. If node is at least 0, Place piece into pieces. If node is less than 0, Place "null" into pieces. If node is at least 0 and item node of gone is 0, Place item node of lefts into queue, Place item node of rights into queue, add 2 to count.
Repeat while the last position of pieces is at least 0.
The tail is the last position of pieces. The tailpiece is item tail of pieces. The isnull is 0. If tailpiece matches "null", set isnull to 1. If isnull is 1, remove the last item from pieces. If isnull is 0, stop.
The line is join pieces with ",". Show line.
Expected stdout
5,4,8,11,null,17,4,7,null,null,null,5