当前位置:网站首页>Leetcode simple question: the minimum total time required to fill a cup
Leetcode simple question: the minimum total time required to fill a cup
2022-07-26 19:06:00 【·Starry Sea】
subject
There is a water dispenser , Cold water can be prepared 、 Warm and hot water . Every second , Can be filled 2 A cup of Different Type of water or 1 Cup any type of water .
I'll give you a subscript from 0 Start 、 The length is 3 Array of integers for amount , among amount[0]、amount[1] and amount[2] Respectively means that it needs to be filled with cold water 、 Number of cups of warm and hot water . Return to fill all cups least Number of seconds .
Example 1:
Input :amount = [1,4,2]
Output :4
explain : Here is a scheme :
The first 1 second : Fill a cup of cold water and a cup of warm water .
The first 2 second : Fill a cup of warm water and a cup of hot water .
The first 3 second : Fill a cup of warm water and a cup of hot water .
The first 4 second : Fill a glass of warm water .
It can be proved that at least 4 Seconds to fill all the cups .
Example 2:
Input :amount = [5,4,4]
Output :7
explain : Here is a scheme :
The first 1 second : Fill a cup of cold water and a cup of hot water .
The first 2 second : Fill a cup of cold water and a cup of warm water .
The first 3 second : Fill a cup of cold water and a cup of warm water .
The first 4 second : Fill a cup of warm water and a cup of hot water .
The first 5 second : Fill a cup of cold water and a cup of hot water .
The first 6 second : Fill a cup of cold water and a cup of warm water .
The first 7 second : Fill a glass of hot water .
Example 3:
Input :amount = [5,0,0]
Output :5
explain : Fill a glass of cold water every second .
Tips :
amount.length == 3
0 <= amount[i] <= 100
source : Power button (LeetCode)
Their thinking
For three kinds of water , We just need to reduce the two remaining largest water cups by one each time , Until the number of all water cups is less than 1.
class Solution:
def fillCups(self, amount: List[int]) -> int:
count=0
while amount[0]>0 or amount[1]>0 or amount[2]>0 :
amount.sort()
amount[1]-=1
amount[2]-=1
count+=1
return count

边栏推荐
- 当前占位,之后再写
- Agenda express | list of sub forum agenda on July 27
- js map使用
- .net CLR GC dynamic loading transient heap threshold calculation and threshold excess calculation
- Data security knowledge system
- LeetCode简单题之第一个出现两次的字母
- 多商户商城系统功能拆解16讲-平台端会员成长值记录
- [interview question] 1384- share 44 JS problems. Half right is a master
- SSM整合-异常处理器和项目异常处理方案
- MySQL日志介绍
猜你喜欢

Likeshop takeout order system is open source, 100% open source, no encryption

ALV screen input option learning

Sentinel 隔离与降级

Complete MySQL database commands

2022年制冷与空调设备运行操作考试模拟100题及模拟考试

How to become an excellent test / development programmer? Focus on planning and then move

JS使用readline来实现终端输入数据

Agenda express | list of sub forum agenda on July 27

2022g1 industrial boiler stoker certificate question bank and simulation examination

Write a thesis and read this one
随机推荐
Interview summary of some large factories
【Swoole系列3.1】进程、线程、协程,面试你被问了吗?
图解用户登录验证流程,写得太好了!
How to become an excellent test / development programmer? Focus on planning and then move
[soft exam] soft exam tutorial + real questions over the years
Summary of some problems encountered in developing WinForm (continuous updating)
Utility website recommendations
详细介绍@GetMapping和@PostMapping的区别
2022G1工业锅炉司炉上岗证题库及模拟考试
2022 Shanghai safety officer C certificate operation certificate examination question bank simulated examination platform operation
Module 8 job message data MySQL table design
MySQL learning notes -2. how to improve the query performance of SQL statements
场景之分页查询设计
NFT数字藏品开发:数字藏品助力企业发展
销量下滑,品牌边缘化,失去“安全牌”的沃尔沃,还能走多远?
2022T电梯修理考试题及在线模拟考试
Lombok common notes
Unity 农场 2 —— 种植系统
JS map usage
FTP protocol