LintCode: 109. 数字三角形 Java
来源:互联网 发布:控制软件 编辑:程序博客网 时间:2024/06/05 19:16
题目大意
给定一个数字三角形,找到从顶部到底部的最小路径和。每一步可以移动到下面一行的相邻数字上。
注意事项
如果你只用额外空间复杂度O(n)的条件下完成可以获得加分,其中n是数字三角形的总行数。
样例
比如,给出下列数字三角形:
[
[2],
[3,4],
[6,5,7],
[4,1,8,3]
]
从顶到底部的最小路径和为11 ( 2 + 3 + 5 + 1 = 11)。
解题思路
总路径最小,则被包含路径之和最小(倒推,顺推不成立)。
public int minimumTotal(int[][] triangle) { // write your code here for (int i=triangle.length-2; i>=0; i--) { for (int j=0; j<triangle[i].length; j++) { triangle[i][j] += Math.min(triangle[i+1][j], triangle[i+1][j+1]); } } return triangle[0][0];}
阅读全文
0 0
- LintCode: 109. 数字三角形 Java
- LintCode Triangle 数字三角形
- lintcode-数字三角形-109
- lintcode ----数字三角形
- lintcode triangle 数字三角形
- 数字三角形-LintCode
- lintcode--数字三角形
- 数字三角形-LintCode
- LintCode 数字三角形
- [LintCode 109] 数字三角形(Python)
- Lintcode-动态规划-数字三角形
- Lintcode 109.数学三角形
- LintCode做题记录- 数字三角形
- LintCode刷题——数字三角形
- java输出数字三角形
- Java实现-数字三角形
- java 数字三角形
- java实现各种数字三角形
- Eclipse使用maven搭建简单spring boot application Hello World
- java分布式系统部署学习(六)ansible Ad-hoc与commands模块
- 前端 ifram 父页面显示子页面内容
- Springboot 之 解决IDEA读取properties配置文件的中文乱码问题
- Ant的安装与配置
- LintCode: 109. 数字三角形 Java
- iOS 动画实战之Lottie动画
- log4j-over-slf4j与slf4j-log4j12共存stack overflow异常分析
- calico 跨主机容器网络通信
- format
- 关于上拉加载的刷新
- Python文件类操作
- 五分钟学GIS | 镶嵌数据集管理影像数据
- Cookie重名问题处理