[leetcode]120. Triangle

原创 2016年08月29日 19:36:57
class Solution {
public:
    int minimumTotal(vector<vector<int>>& triangle) 
    {
        int n=triangle.size();
        
        for(int i=1;i<n;i++)
        {
            triangle[i][0]+=triangle[i-1][0];
            for(int j=1;j<i;j++)
                triangle[i][j]=triangle[i][j]+min(triangle[i-1][j-1],triangle[i-1][j]);
            triangle[i][i]+=triangle[i-1][i-1];
        }
        
        int sum=triangle[n-1][0];
        for(int i=0;i<n;i++)
        {
            if(triangle[n-1][i]<sum)
                sum=triangle[n-1][i];
        }
        return sum;
        
    }
};

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

【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 三角形最小路径和

给出一个三角形(数据数组),找出从上往下的最小路径和。每一步只能移动到下一行中的相邻结点上。空间复杂度要求O(n)。...

leetcode_question_120 Triangle

Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n...
  • doc_sgl
  • doc_sgl
  • 2013年09月16日 10:03
  • 2048

[leetcode]120. Triangle(Java)

https://leetcode.com/problems/triangle/#/description Given a triangle, find the minimum pat...

LeetCode 120. Triangle 解题报告

LeetCode 120. Triangle 解题报告题目描述Given a triangle, find the minimum path sum from top to bottom. Each ...

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
举报原因:
原因补充:

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