[LeetCode] 120. Triangle

原创 2016年08月31日 09:06:10

思路:
用一个类似DP的bottom up策略, 当前层当前节点的最小值应该是它两个孩子的最小值加上他自己的值.

int minimumTotal(vector<vector<int>>& triangle) {
    if (triangle.empty())
        return 0;
    vector<int> bot(triangle.back());
    for (int i = n - 2; i >= 0; i--) 
        for (int j = 0; j <= i; j++)
            bot[j] = min(bot[j], bot[j + 1]) + triangle[i][j];
    return bot[0];
}

相关文章推荐

LeetCode 120. Triangle 动态规划

120. Triangle Given a triangle, find the minimum path sum from top to bottom. Each step you may mo...

leetcode120. Triangle

120. TriangleGiven a triangle, find the minimum path sum from top to bottom. Each step you may move ...

【leetcode】120. Triangle

Difficulty:medium Given a triangle, find the minimum path sum from top to bottom. Each step you m...

LeetCode120 Triangle

详细见:leetcode.com/problems/triangle Java Solution: github package leetcode; /* * Given a t...
  • zxwtry
  • zxwtry
  • 2017年05月04日 22:24
  • 119

[LeetCode]120.Triangle

【题目】 Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adj...

LeetCode(120) Triangle

题目Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent...
  • fly_yr
  • fly_yr
  • 2015年11月14日 15:37
  • 395

LeetCode: Triangle [120]

【题目】 Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adja...

LeetCode 62/63/120/64 Unique PathsI/II Triangle/Min sum Path/Rectangle Area--DP

一:unique Path 题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the ...

【LeetCode-面试算法经典-Java实现】【120-Triangle(三角形)】

【120-Triangle(三角形)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题  Given a triangle, find the minimum path sum...

LeetCode 120 Triangle

Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:[LeetCode] 120. Triangle
举报原因:
原因补充:

(最多只允许输入30个字)