1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/房屋偷盗 [Gu0c2T].html
2022-03-29 12:43:11 +08:00

36 lines
1.5 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>一个专业的小偷,计划偷窃沿街的房屋。每间房内都藏有一定的现金,影响小偷偷窃的唯一制约因素就是相邻的房屋装有相互连通的防盗系统,<strong>如果两间相邻的房屋在同一晚上被小偷闯入,系统会自动报警</strong></p>
<p>给定一个代表每个房屋存放金额的非负整数数组 <code>nums</code>&nbsp;,请计算<strong>&nbsp;不触动警报装置的情况下 </strong>,一夜之内能够偷窃到的最高金额。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums =<strong> </strong>[1,2,3,1]
<strong>输出:</strong>4
<strong>解释:</strong>偷窃 1 号房屋 (金额 = 1) ,然后偷窃 3 号房屋 (金额 = 3)。
&nbsp; 偷窃到的最高金额 = 1 + 3 = 4 。</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums =<strong> </strong>[2,7,9,3,1]
<strong>输出:</strong>12
<strong>解释:</strong>偷窃 1 号房屋 (金额 = 2), 偷窃 3 号房屋 (金额 = 9),接着偷窃 5 号房屋 (金额 = 1)。
&nbsp; 偷窃到的最高金额 = 2 + 9 + 1 = 12 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
<li><code>0 &lt;= nums[i] &lt;= 400</code></li>
</ul>
<p>&nbsp;</p>
<p><meta charset="UTF-8" />注意:本题与主站 198&nbsp;题相同:&nbsp;<a href="https://leetcode-cn.com/problems/house-robber/">https://leetcode-cn.com/problems/house-robber/</a></p>