博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【leetcode】Triangle
阅读量:4361 次
发布时间:2019-06-07

本文共 918 字,大约阅读时间需要 3 分钟。

Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.

For example, given the following triangle

[
[2],
[3,4],
[6,5,7],
[4,1,8,3]
]
The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11).

Note:

Bonus point if you are able to do this using only O(n) extra space, where n is the total number of rows in the triangle.

 

1 class Solution{ 2 public: 3     int minimumTotal(vector
> &triangle){ 4 int n=triangle.size(); 5 if(n==0) return 0; 6 7 int *sum=new int[n+1]; 8 9 sum[0]=triangle[0][0];10 11 for(int i=1;i
0;j--)15 sum[j]=min(sum[j],sum[j-1])+triangle[i][j];16 sum[0]=sum[0]+triangle[i][0];17 }18 19 int min=INT_MAX;20 for(int i=0;i

 

转载于:https://www.cnblogs.com/jawiezhu/p/4514963.html

你可能感兴趣的文章
[TODO]Ubuntu挂载硬盘之后出现乱码以及文件丢失现象
查看>>
poj1417 True Liars
查看>>
线程池
查看>>
配置APP的图标
查看>>
IOS5中的Safari不兼容Javascript中的Date问题,做下笔录吧!奶奶的,折腾我半天!...
查看>>
利用element-ui封装地址输入的组件
查看>>
【线段树区间最值单点更新模板】BNUOJ 52965 E Excellent Engineers
查看>>
String、StringBuffer与StringBuilder之间区别
查看>>
Timer.3 - Binding arguments to a handler
查看>>
linux 判断变量是否相等方法
查看>>
只能为浮点数的正则表达式
查看>>
Android之指南针学习 分类: Android开发 ...
查看>>
android学习和广告平台赚钱zz 分类: Android其他 ...
查看>>
第7章例7-13
查看>>
推荐几本产品类的书
查看>>
VC++一些开发心得与调试技巧
查看>>
python 归纳 (二八)_python测试使用快速上手
查看>>
oracle 11g虚拟机安装环境配置脚本
查看>>
高并发的初识和想法
查看>>
[HihoCoder-1424] Asa's Chess Problem
查看>>