Python 刷Leetcode题库,顺带学英语单词(43)

简介: Python 刷Leetcode题库,顺带学英语单词(43)

House Robber


You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.     [#198]


Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police.


   Example 1:

   Input: [1,2,3,1]

   Output: 4

   Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).

   Total amount you can rob = 1 + 3 = 4.


   Example 2:

   Input: [2,7,9,3,1]

   Output: 12

   Explanation: Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5

   (money = 1).

   Total amount you can rob = 2 + 9 + 1 = 12.


House Robber II


You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.   [#213]


Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police.


   Example 1:

   Input: [2,3,2]

   Output: 3

   Explanation: You cannot rob house 1 (money = 2) and then rob house 3 (money = 2), because they are adjacent houses.


   Example 2:

   Input: [1,2,3,1]

   Output: 4

Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3). Total amount you can rob = 1 + 3 = 4.



目录
相关文章
|
19天前
|
存储 索引 Python
leetcode-350:两个数组的交集 II(python中Counter的用法,海象运算符:=)
leetcode-350:两个数组的交集 II(python中Counter的用法,海象运算符:=)
33 0
|
7月前
|
测试技术
LeetCode字符串题库 之 罗马数字转整数
LeetCode字符串题库 之 罗马数字转整数
LeetCode字符串题库 之 罗马数字转整数
|
13天前
|
存储 数据可视化 算法
最新Python-Matplotlib可视化(9)——精通更多实用图形的绘制,2024年最新小米面试题库
最新Python-Matplotlib可视化(9)——精通更多实用图形的绘制,2024年最新小米面试题库
最新Python-Matplotlib可视化(9)——精通更多实用图形的绘制,2024年最新小米面试题库
|
14天前
|
物联网 Python
2024年Python最全信息技术导论——物联网技术习题整理(1),Python面试题库
2024年Python最全信息技术导论——物联网技术习题整理(1),Python面试题库
2024年Python最全信息技术导论——物联网技术习题整理(1),Python面试题库
|
19天前
|
API Python
[AIGC] 使用Python刷LeetCode:常用API及技巧指南
[AIGC] 使用Python刷LeetCode:常用API及技巧指南
|
19天前
|
存储 JSON 数据可视化
Python期末复习题库(下)——“Python”
Python期末复习题库(下)——“Python”
|
19天前
|
数据采集 IDE 开发工具
Python期末复习题库(上)——“Python”
Python期末复习题库(上)——“Python”
|
19天前
|
算法 索引 Python
leetcode-138:复制带随机指针的链表 (python中copy与deepcopy区别)
leetcode-138:复制带随机指针的链表 (python中copy与deepcopy区别)
39 0
|
11月前
|
存储 算法 C++
(C语言版)力扣(LeetCode)题库1-5题解析
给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。
|
11月前
【Leetcode】题库-爽刷简单题(1)
【Leetcode】题库-爽刷简单题(1)
66 0