国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

LeetCode:triangle

2019-11-08 02:46:20
字體:
來源:轉載
供稿:網友

鏈接:https://www.nowcoder.com/PRactice/2b7995aa4f7949d99674d975489cb7da?tpId=46&tqId=29060&tPage=1&rp=1&ru=/ta/leetcode&qru=/ta/leetcode/question-ranking 來源:牛客網

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 is11(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) { for(int i=triangle.size()-2;i>=0;--i) { for(int j=0;j<i+1;++j) { triangle[i][j] = min(triangle[i+1][j],triangle[i+1][j+1])+triangle[i][j]; } } return triangle[0][0]; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 麻江县| 苗栗市| 若尔盖县| 清河县| 陕西省| 梅州市| 灵璧县| 茶陵县| 游戏| 永安市| 富顺县| 乃东县| 桐梓县| 钟祥市| 河北区| 广饶县| 富宁县| 洛阳市| 乳源| 梁河县| 德令哈市| 潮安县| 若羌县| 荥阳市| 弥渡县| 张家口市| 彩票| 石门县| 新竹市| 莒南县| 莲花县| 清徐县| 维西| 福鼎市| 文水县| 桂林市| 内乡县| 望城县| 牟定县| 清水河县| 仲巴县|