数字三角形-LintCode
来源:互联网 发布:mac上eclipse汉化 编辑:程序博客网 时间:2024/06/05 15:22
给定一个数字三角形,找到从顶部到底部的最小路径和。每一步可以移动到下面一行的相邻数字上。
样例
比如,给出下列数字三角形:
[
[2],
[3,4],
[6,5,7],
[4,1,8,3]
]
从顶到底部的最小路径和为11 ( 2 + 3 + 5 + 1 = 11)。
#ifndef C109_H#define C109_H#include<iostream>#include<vector>using namespace std;class Solution {public: /** * @param triangle: a list of lists of integers. * @return: An integer, minimum path sum. */ int minimumTotal(vector<vector<int>> &triangle) { // write your code here int len = triangle.size(); for (int i = len - 2; i >= 0; --i) { for (int j = 0; j < triangle[i].size(); ++j) { triangle[i][j] = minVal(triangle[i + 1][j], triangle[i + 1][j + 1]) + triangle[i][j]; } } return triangle[0][0]; } int minVal(int m, int n) { return m < n ? m : n; }};#endif
阅读全文
0 0
- LintCode Triangle 数字三角形
- lintcode-数字三角形-109
- lintcode ----数字三角形
- lintcode triangle 数字三角形
- 数字三角形-LintCode
- lintcode--数字三角形
- 数字三角形-LintCode
- LintCode 数字三角形
- [LintCode 109] 数字三角形(Python)
- Lintcode-动态规划-数字三角形
- LintCode: 109. 数字三角形 Java
- LintCode做题记录- 数字三角形
- LintCode刷题——数字三角形
- LintCode-三角形计数
- lintcode(382)三角形计数
- lintcode 三角形计数
- LintCode之三角形计数
- Lintcode三角形计数
- ajax上传图片+FastDFS
- MySQL查询语句的45道练习
- JS时间方法,undefined和null的区别
- 计算机视觉领域的一些牛人博客,研究机构等的网站链接 && 机器学习算法中文视频教程
- maven工程打包后 properties未能读到pom properties
- 数字三角形-LintCode
- 今天使用Django测试第一个小例子的时候,遇到了NameError: name 'include' is not defined错误
- CKEditor与CKFinder整合并实现文件上传功能
- Linux platform
- 数组的简单解析
- $.format
- 抽签
- spring常出现的异常
- LeetCode 198. [DP]House Robber