Leetcode 120 Triangle
来源:互联网 发布:单片机 红外发射 编辑:程序博客网 时间:2024/05/16 15:18
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.
class Solution {public: int minimumTotal(vector<vector<int>>& triangle) { vector<vector<int>> dp=triangle; for(int i=1;i<dp.size();i++) { for(int j=0;j<dp[i].size();j++) { vector<int> temp; if(j!=0) temp.push_back(dp[i-1][j-1]); if(j!=dp[i].size()-1) temp.push_back(dp[i-1][j]); sort(temp.begin(),temp.end()); dp[i][j]=temp[0]+dp[i][j]; } } sort(dp[dp.size()-1].begin(),dp[dp.size()-1].end()); return dp[dp.size()-1][0]; }};
1 0
- Leetcode 120 Triangle
- LeetCode 120: Triangle
- LeetCode(120)Triangle
- LeetCode: Triangle [120]
- LeetCode 120 Triangle
- LeetCode 120 Triangle
- [leetcode 120] Triangle
- [Leetcode 120, Medium] Triangle
- leetcode || 120、Triangle
- Triangle - LeetCode 120
- Leetcode[120]-Triangle
- LeetCode(120) Triangle
- Leetcode #120 Triangle
- [leetcode-120]Triangle(c++)
- leetcode 120: Triangle
- 【LeetCode】(120)Triangle (Medium)
- [leetcode] 120 Triangle
- LeetCode 120: Triangle
- [ElasticSearch]映射(Mapping)
- Android develop 之AsyncTask
- html页面异步加载时,显示预加载
- 【SSH进阶之路】Hibernate基本原理(一)
- 模式十:迭代器模式(Iterator Pattern)——顺序访问聚合对象元素
- Leetcode 120 Triangle
- VS2010 MFC中对Access数据库基本操作
- web项目 action中获得spring ioc容器
- 移除数组中的特定数
- 定期清理服务器log的脚本
- web前端(001_滚动效果)
- HttpURLConnection类的保持session会话
- Android开发—RadioGroup中RadioButton默认选中问题
- [从头学绘画] 第37节 跆拳道二十四品势之8-花郞