Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.22 KB | None | 0 0
  1. def minimum_total(triangle)
  2.   dp = triangle.last
  3.  
  4.   (triangle.size-2).downto(0).each do |i|
  5.     (0...triangle[i+1].size-1).each do |j|
  6.       dp[j] = [dp[j], dp[j+1]].min + triangle[i][j]
  7.     end
  8.   end
  9.  
  10.   dp[0]
  11. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement