Leetcode 120 Triangle
2015-06-21 09:55
197 查看
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
The minimum path sum from top to bottom is
设置数组m为最后一行,然后由下至上,转移方程 m[j] = t[i][j] + min(m[j],m[j+1])
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).
设置数组m为最后一行,然后由下至上,转移方程 m[j] = t[i][j] + min(m[j],m[j+1])
var minimumTotal = function(t) { var m = t[t.length - 1] for (var i=t.length-2;i>=0;i--) for(var j=0;j<=i;j++) m[j] = t[i][j] + Math.min(m[j],m[j+1]) return m[0] }
相关文章推荐
- leetcode--House Robber II
- 文本编码
- gnuplot 入门教程 1
- 【麦可网】Cocos2d-X跨平台游戏开发学习笔记---第十二课:Cocos2D-X内存管理1-3
- 第4章 对象与类
- C++ 与 C
- 软件工程读后感
- 人,绩效和职业道德读后感
- JAVA集合中不可重复性与是否有顺序
- HDU5274 Dylans loves tree(树链剖分)很巧的点权更新
- C++语言基础 例程 字符串类
- C++语言基础 例程 函数模板
- Osal提供定时服务的函数
- 读书与思考
- C++语言基础 例程 函数重载
- COJ 0026 汉诺塔问题
- 二叉树的三种遍历方式:递归、栈、循环
- C++语言基础 例程 有默认参数的函数
- 二叉树的三种遍历方式:递归、栈、循环 分类: C/C++ 数据结构与算法 2015-06-21 09:47 269人阅读 评论(0) 收藏
- 谷歌与百度首页图标搜集