当前位置:网站首页>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

边栏推荐
- 5 best overseas substitutes for WPS Office
- Agenda express | list of sub forum agenda on July 27
- NFT数字藏品开发:数字藏品助力企业发展
- 一文详解MES系统给企业带来的5大好处,附应用场景
- likeshop外卖点餐系统开源啦100%开源无加密
- 2022年焊工(初级)操作证考试题库及模拟考试
- Arrangement of information security emergency plan
- rancher部署kubernetes集群
- Redis core principles
- Module 8 job message data MySQL table design
猜你喜欢

支持代理直连Oracle数据库,JumpServer堡垒机v2.24.0发布

MySQL - multi table query and case explanation

NFT digital collection system development: sold out when online, and netizens "spike" Digital Collections

2022 welder (elementary) operation certificate examination question bank and simulation examination

MPLS experiment

Microsoft silently donated $10000 to curl, which was not notified until half a year later

Advanced template (runner's notes)

JS uses readLine to realize terminal input data

销量下滑,品牌边缘化,失去“安全牌”的沃尔沃,还能走多远?

Arrangement of information security emergency plan
随机推荐
MySQL数据库命令大全
Agenda express | list of sub forum agenda on July 27
Kubectl common commands and simple explanations
2022t elevator repair examination questions and online simulation examination
Write a thesis and read this one
Neural network learning (2) introduction 2
Racher deploys kubernetes cluster
Lombok common notes
销量下滑,品牌边缘化,失去“安全牌”的沃尔沃,还能走多远?
Seata 入门简介
Paged query design of scenarios
议程速递 | 7月27日分论坛议程一览
2022T电梯修理考试题及在线模拟考试
2022g1 industrial boiler stoker certificate question bank and simulation examination
当前占位,之后再写
ZbxTable 2.0 重磅发布!6大主要优化功能!
[soft exam] soft exam tutorial + real questions over the years
【Swoole系列3.1】进程、线程、协程,面试你被问了吗?
Brian behrendorf, general manager of openssf Foundation: it is estimated that there will be 420million open sources in 2026
The pit of mpc5744p reports an error, RTOS cannot be started, and there is a clock source problem