Solved LeetCode program · 113 of 1,000
#0113 · Path Sum II
Original English source
Keep a shared values holding 5, 4, 8, 11, 6, 4, 7, 2, 5, and 1. Keep a shared lefts holding 1, 3, 5, 6, -1, 8, -1, -1, -1, and -1. Keep a shared rights holding 2, 4, -1, 7, -1, 9, -1, -1, -1, and -1. Keep a shared path as an empty list of whole numbers. Keep a shared answers as an empty list of text. Keep a shared target of 0. Keep a shared line as empty text. Set target to 22.
To render from spot (a whole number) with last (a whole number). If spot is more than last, return. If the length of line is more than 0, Place "," into line. The piece is format whole number item spot of path as text. Place piece into line. Render from spot plus 1 with last.
To store answer. Set line to empty text. The lastpath is the last position of path. Render from 0 with lastpath. The copy is a copy of line. Place copy into answers.
To seek from node (a whole number) with total (a whole number). If node is less than 0, return. The sum is total plus item node of values. Place item node of values into path. The left is item node of lefts. The right is item node of rights. If left is -1 and right is -1 and sum is target, store answer. If left is at least 0, seek from left with sum. If right is at least 0, seek from right with sum. Remove the last item from path.
Seek from 0 with 0. For each answer in answers, show answer.
Expected stdout
5,4,11,2 5,8,4,5