avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • Resume
  • Archives
  • Categories
  • Photos
  • Music



{{ date }}

{{ time }}

avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • 主页
  • Resume
  • Archives
  • Categories
  • Photos
  • Music

2335. The shortest total time to be filled with a cup One question daily

  2024-01-01        
字数统计: 291字   |   阅读时长: 1min

topic:

2023-02-11.png
2335. The shortest total time to be filled with a cup.md

Thought:

  1. This question is very simple,但是我好像没用贪心的Thought。Look at the second test case and find it found,In fact, the minimum number of seconds is to avoid a certain number as much as possible0。
    So keep sorting,Always operate the two largest numbers。This sending can also be used for DoriamountCase,But because of sorting,I don’t know if it can be used for a large number。
    Look atylbBig,和我一样但是Big细节处理得很好,Two fewer judgments than me,Then it seems that the classification discussion method below may be a solution to the difficult situation。
  2. mathematical method?Sort the number of drinks from small to large,Set the quantity x,y,z。Our goal is to match the different drinks as much as possible。
    like$x+y<=z$,The answer isz。like反之,Then set$t=(x+y-z)$,t是偶数The answer is
    $ \frac{t−1}{2} +z$Plus one

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution:
def fillCups(self, amount: List[int]) -> int:
amount.sort()
count = 0
# Try to avoid returning0
while amount[-1] > 0:
if amount[-1] > 0 and amount[1] > 0:
amount[-1] -= 1
amount[1] -= 1
count += 1
if amount[-1] > 0 and amount[1] == 0:
return count + amount[-1]
amount.sort()
return count
ylb-golang
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import "sort"

func fillCups(amount []int) int {
ans := 0
for amount[0] + amount[1] + amount[2] > 0 {
sort.Ints(amount)
ans ++
amount[2] --
if amount[1] > 0{
amount[1] --
}
}
return ans
}
  • Python
  • answer
  • One question daily
  • golang
  • dp

扫一扫,分享到微信

微信分享二维码
2331Calculate the value of the Boolean binary tree One question daily
2527.Query arrayXorBeautiful value Zhou Sai Third Question
目录
  1. 1. topic:
  2. 2. Thought:
  3. 3. Code:

150 篇 | 131.7k
次 | 人
这里自动载入天数这里自动载入时分秒
2022-2025 loong loong | 新南威尔士龙龙号