Skip to content

Commit a84205c

Browse files
committed
feat: add more
1 parent ef3952e commit a84205c

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// https://leetcode.com/problems/minimum-amount-of-time-to-fill-cups
2-
//
2+
//
33
// You have a water dispenser that can dispense cold, warm, and hot water. Every second, you can either fill up `2` cups with **different** types of water, or `1` cup of any type of water.
4-
//
4+
//
55
// You are given a **0-indexed** integer array `amount` of length `3` where `amount[0]`, `amount[1]`, and `amount[2]` denote the number of cold, warm, and hot water cups you need to fill respectively. Return _the **minimum** number of seconds needed to fill up all the cups_.
6-
//
6+
//
77
// **Example 1:**
8-
//
8+
//
99
// ```
1010
// **Input:** amount = [1,4,2]
1111
// **Output:** 4
@@ -16,9 +16,9 @@
1616
// Second 4: Fill up a warm cup.
1717
// It can be proven that 4 is the minimum number of seconds needed.
1818
// ```
19-
//
19+
//
2020
// **Example 2:**
21-
//
21+
//
2222
// ```
2323
// **Input:** amount = [5,4,4]
2424
// **Output:** 7
@@ -31,24 +31,36 @@
3131
// Second 6: Fill up a cold cup, and a warm cup.
3232
// Second 7: Fill up a hot cup.
3333
// ```
34-
//
34+
//
3535
// **Example 3:**
36-
//
36+
//
3737
// ```
3838
// **Input:** amount = [5,0,0]
3939
// **Output:** 5
4040
// **Explanation:** Every second, we fill up a cold cup.
4141
// ```
42-
//
42+
//
4343
// **Constraints:**
44-
//
44+
//
4545
// * `amount.length == 3`
4646
// * `0 <= amount[i] <= 100`
4747

4848
pub fn fill_cups(amount: Vec<i32>) -> i32 {
49-
49+
let mut res = 0;
50+
let mut amount_clone = amount.clone();
51+
loop {
52+
if amount_clone.iter().max().unwrap() < &1 {
53+
return res;
54+
}
55+
amount_clone.sort_unstable();
56+
amount_clone[2] -= 1;
57+
amount_clone[1] -= 1;
58+
res += 1;
5059
}
60+
}
5161

5262
#[test]
5363
pub fn t1() {
64+
assert_eq!(fill_cups(vec![1, 4, 2]), 4);
65+
assert_eq!(fill_cups(vec![5, 4, 4]), 7);
5466
}

Array/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,4 @@ mod _2248_intersection_of_multiple_arrays;
155155
mod _2255_count_prefixes_of_a_given_string;
156156
mod _2293_min_max_game;
157157
mod _2319_check_if_matrix_is_x_matrix;
158+
mod _2335_minimum_amount_of_time_to_fill_cups;

0 commit comments

Comments
 (0)