原题

思路:

dp,从下往上依次取得最小的,取到最上面的,就是一条最小的路径。

class Solution
{
public:
int minimumTotal(vector<vector<int>> &triangle)
{
int rowSize = triangle.size();
int colSize;
if (rowSize == 0)
return -1;
if (rowSize == 1)
return triangle[0][0]; for (int row = rowSize - 2; row >= 0; row--)
{
colSize = triangle[row].size();
for (int col = 0; col < colSize; col++)
{
triangle[row][col] +=
min(triangle[row + 1][col], triangle[row + 1][col + 1]);
}
}
return triangle[0][0];
}
};

[leetcode] 120. Triangle (Medium)的更多相关文章

  1. LeetCode 120. Triangle (三角形)

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  2. LeetCode: 51. N-Queens(Medium)

    1. 原题链接 https://leetcode.com/problems/n-queens/description/ 2. 题目要求 游戏规则:当两个皇后位于同一条线上时(同一列.同一行.同一45度 ...

  3. leetcode之旅(11)-Integer to Roman

    题目描述: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range fr ...

  4. LeetCode之旅(13)-Valid Anagram

    题目介绍: Given two strings s and t, write a function to determine if t is an anagram of s. For example, ...

  5. LeetCode高频题目(100)汇总-Java实现

    LeetCode高频题目(100)汇总-Java实现       LeetCode高频题目(100)汇总-Java实现 目录 第01-50题 [Leetcode-easy-1] Two Sum [Le ...

  6. Leetcode之动态规划(DP)专题-详解983. 最低票价(Minimum Cost For Tickets)

    Leetcode之动态规划(DP)专题-983. 最低票价(Minimum Cost For Tickets) 在一个火车旅行很受欢迎的国度,你提前一年计划了一些火车旅行.在接下来的一年里,你要旅行的 ...

  7. leetcode解题报告(2):Remove Duplicates from Sorted ArrayII

    描述 Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For ex ...

  8. Leetcode之动态规划(DP)专题-647. 回文子串(Palindromic Substrings)

    Leetcode之动态规划(DP)专题-647. 回文子串(Palindromic Substrings) 给定一个字符串,你的任务是计算这个字符串中有多少个回文子串. 具有不同开始位置或结束位置的子 ...

  9. Leetcode之动态规划(DP)专题-474. 一和零(Ones and Zeroes)

    Leetcode之动态规划(DP)专题-474. 一和零(Ones and Zeroes) 在计算机界中,我们总是追求用有限的资源获取最大的收益. 现在,假设你分别支配着 m 个 0 和 n 个 1. ...

随机推荐

  1. Delphi用Socket API实现路由追踪

    Windows自带的Tracert是向远程主机发送ICMP包进行追踪,但是目前很多主机关闭了ICMP答复,这个工具不太好使了~~~~~原理咱知道,正规的Trace不就是发送TTL依次递增的UDP包吗? ...

  2. 用java打印日历

    来自<java核心技术卷一> /** * Created by wangbin10 on 2019/1/3. * 打印当月日历 */ public class CalendarTest { ...

  3. Spring Boot:使用Redis存储技术

    综合概述 Redis是一个开源免费的高性能key-value数据库,读取速度达110000次/s,写入速度达81000次/s.Redis支持丰富的数据类型,如Lists, Hashes, Sets 及 ...

  4. 使用BurpSuite的Collaborator查找.Onion隐藏服务的真实IP地址

    本文转载!!! 原文地址:http://www.4hou.com/technology/10367.html 翻译来自:http://digitalforensicstips.com/2017/11/ ...

  5. spring cloud 系列第6篇 —— zuul 服务网关 (F版本)

    源码Gitub地址:https://github.com/heibaiying/spring-samples-for-all 一.zuul简介 1.1 API 网关 api 网关是整个微服务系统的门面 ...

  6. 纯异步nodejs文件夹(目录)复制

    思路: 1.callback 驱动 2.递归所有需要复制文件 3.在一定阀值下并发复制文件 4.运行需要安装 async.js     npm install async 代码如下: var asyn ...

  7. 对比Hashtable,HashMap,TreeMap,谈谈对HashMap的理解

    都实现了Map接口,存储的内容是基于key-value的键值对映射,一个映射不能有重复的键,一个键最多只能映射一个值. 1.初始化的时候:HashTable在不指定容量的情况下的默认容量是11,且不要 ...

  8. RT-Thread的CPU占用率查看

    今天看到朋友的博客,他在描述RT-Thread钩子函数时,简单提了下RT-Thread中CPU占用,没有具体描述,所以我在这里做下补充. RT-Thread查看CPU使用率时,我知道的有这种方法. 大 ...

  9. Web自动化测试 一

    Web自动化测试 一.为什么要进行web自动化测试 接口测试只能测试后端返回的数据,定位的是后端开发工程师的问题.如果前段出现了问题,我们要使用web测试去发现错误. 具体定位的问题有: 显示的数据: ...

  10. decimal.ToString()问题

    decimal dt = 1.00M;            decimal dt1 = 1M;                         bool d = dt == dt1;         ...