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).

这道题本身不难,它要求只使用O(n)的空间。

对于这一点,不要误解,之前有一题pascal三角的题目就是误解了。

如果限制使用的O(n)的空间,那么很有可能是对一个O(n)的空间进行重复的使用。

这道题要小心的是,对这个O(n)空间进行重复使用的时候,往往从头开始使用时不行的,

此时可以考虑从尾部往前使用,因为第k次循环可能只使用k的空间,那么对于k+1次循环来说,就有

n-k的空间可以利用

leetcode Triangle及其思考的更多相关文章

  1. [LeetCode] Triangle 三角形

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

  2. leetcode — triangle

    /** * Source : https://oj.leetcode.com/problems/triangle/ * * * Given a triangle, find the minimum p ...

  3. [leetcode]Triangle @ Python

    原题地址:https://oj.leetcode.com/problems/triangle/ 题意: Given a triangle, find the minimum path sum from ...

  4. LeetCode - Triangle

    题目: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjace ...

  5. LeetCode -- Triangle 路径求最小和( 动态规划问题)

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

  6. LeetCode Triangle 三角形(最短路)

    题意:给一个用序列堆成的三角形,第n层的元素个数为n,从顶往下,每个元素可以选择与自己最近的两个下层元素往下走,类似一棵二叉树,求最短路. [], [,4], [6,,7], [4,,8,3] 注意: ...

  7. leetcode—triangle

    1.题目描述 Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adj ...

  8. LeetCode: Triangle 解题报告

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

  9. LeetCode 解题报告索引

    最近在准备找工作的算法题,刷刷LeetCode,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考.根据我自己做的进度持续更新中......                        ...

随机推荐

  1. Shell指令

    Shell指令 1.Shell原理图 2.Shell指令的基本语法 Shell指令 Shell –选项 参数 Shell –选项 Shell参数 3.常用的Shell指令 1)ls指令:显示文件信息 ...

  2. double与int类型自动转换

    package com.abc.test; public class SumTest { public static void main(String[] args) { //题目A:2+4+6+8+ ...

  3. Object-C编译的Protobuf

    因工作需要,要编译Object-C可用的Protocbuf,开始查资料, http://www.cnblogs.com/uniy/archive/2011/12/21/2296405.html 结果执 ...

  4. 方便实用的jQuery checkbox复选框全选功能

    // 主复选框 <input type="checkbox" id="ck" name="ckAll">// 子复选框项 < ...

  5. aspx利用cookie值来停止silverlight中的计时器

    一.silverlight与silverlight中可以利用委托(delegate)来刷新frame.Refresh() 1.在子类中定义委托捕捉关闭事件按钮 public delegate void ...

  6. hbase meta表的结构

    下面看下hbase:meta 表的结构,hbase:meta表中,保存了每个表的region地址,还有一些其他信息,例如region的名字,HRegionInfo,服务器的信息.hbase:meta表 ...

  7. TDirectory.CreateDirectory 完整、严谨的创建一个目录

    描述:创建一个目录,不包含多级目录(多级目录使用System.SysUtils.ForceDirectories,Vcl.FileCtrl.ForceDirectories已过时) procedure ...

  8. Django模版进阶

    # -*- coding: utf-8 -*-from django.shortcuts import renderdef home(request): string = "测试" ...

  9. selenium for python 所有方法

    先列出selenium所有方法,然后挨个使用!说明 add_cookieapplication_cachebackcapabilitiesclosecommand_executorcreate_web ...

  10. 内部技术分享的 PPT

    本文的基础是搞了一次内部的技术分享,在此也分享一下本次的PPT的一些内容.先列一下大概内容吧. EF-Code First API(WCF.WebAPI) Xaml MVVM AOP Xamarin. ...