Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def minimum_total(triangle)
- dp = triangle.last
- (triangle.size-2).downto(0).each do |i|
- (0...triangle[i+1].size-1).each do |j|
- dp[j] = [dp[j], dp[j+1]].min + triangle[i][j]
- end
- end
- dp[0]
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement