国产探花免费观看_亚洲丰满少妇自慰呻吟_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]; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新化县| 宁武县| 托克托县| 哈巴河县| 兖州市| 亳州市| 通化市| 浮梁县| 龙门县| 于都县| 马关县| 鄂尔多斯市| 淅川县| 从江县| 和田市| 印江| 宕昌县| 寿光市| 漠河县| 海兴县| 三都| 阿拉善盟| 许昌县| 刚察县| 崇义县| 和硕县| 浙江省| 孝昌县| 永德县| 康平县| 黄浦区| 龙游县| 龙口市| 江安县| 宝丰县| 育儿| 远安县| 梓潼县| 太原市| 金溪县| 奈曼旗|