mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			49 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给定一个三角形 <code>triangle</code> ,找出自顶向下的最小路径和。</p>
 | 
						||
 | 
						||
<p>每一步只能移动到下一行中相邻的结点上。<strong>相邻的结点 </strong>在这里指的是 <strong>下标</strong> 与 <strong>上一层结点下标</strong> 相同或者等于 <strong>上一层结点下标 + 1</strong> 的两个结点。也就是说,如果正位于当前行的下标 <code>i</code> ,那么下一步可以移动到下一行的下标 <code>i</code> 或 <code>i + 1</code> 。</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>triangle = [[2],[3,4],[6,5,7],[4,1,8,3]]
 | 
						||
<strong>输出:</strong>11
 | 
						||
<strong>解释:</strong>如下面简图所示:
 | 
						||
   <strong>2</strong>
 | 
						||
  <strong>3</strong> 4
 | 
						||
 6 <strong>5</strong> 7
 | 
						||
4 <strong>1</strong> 8 3
 | 
						||
自顶向下的最小路径和为 11(即,2 + 3 + 5 + 1 = 11)。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 2:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>triangle = [[-10]]
 | 
						||
<strong>输出:</strong>-10
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>1 <= triangle.length <= 200</code></li>
 | 
						||
	<li><code>triangle[0].length == 1</code></li>
 | 
						||
	<li><code>triangle[i].length == triangle[i - 1].length + 1</code></li>
 | 
						||
	<li><code>-10<sup>4</sup> <= triangle[i][j] <= 10<sup>4</sup></code></li>
 | 
						||
</ul>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>进阶:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li>你可以只使用 <code>O(n)</code> 的额外空间(<code>n</code> 为三角形的总行数)来解决这个问题吗?</li>
 | 
						||
</ul>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><meta charset="UTF-8" />注意:本题与主站 120 题相同: <a href="https://leetcode-cn.com/problems/triangle/">https://leetcode-cn.com/problems/triangle/</a></p>
 |