Solved LeetCode program · 253 of 1,000
#0337 · House Robber III
Original English source
Keep a shared values holding 3, 2, 3, -1, 3, -1, and 1. 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. Keep a shared robbed as an empty list of whole numbers.
For every spot from 0 to 6.
Place 0 into robbed.
Keep a shared aside as an empty list of whole numbers.
For every spot from 0 to 6.
Place 0 into aside.
To score from node (a whole number). If node is less than 0, return. The left is item node of lefts. The right is item node of rights. If left is at least 0, score from left. If right is at least 0, score from right. The here is item node of values. The leftaside is 0. The lefttake is 0. The rightaside is 0. The righttake is 0. If left is at least 0, set leftaside to item left of aside. If left is at least 0, set lefttake to item left of robbed. If right is at least 0, set rightaside to item right of aside. If right is at least 0, set righttake to item right of robbed. The bestleft is the larger of leftaside and lefttake. The bestright is the larger of rightaside and righttake. Set item node of robbed to here plus leftaside plus rightaside. Set item node of aside to bestleft plus bestright.
Score from 0. The answer is the larger of item 0 of robbed and item 0 of aside. Show answer.
Expected stdout
7