Skip to content

Commit eb43828

Browse files
authored
Added solution for 2144
1 parent 85214da commit eb43828

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
impl Solution {
2+
// Sort the list in reverse order. Then add values of all elements in output variable, but skip every 3rd element since every 3rd element can be the free item with the 2 items before it
3+
pub fn minimum_cost(mut cost: Vec<i32>) -> i32 {
4+
let mut output = 0;
5+
cost.sort();
6+
cost.reverse();
7+
for (index, c) in cost.iter().enumerate() {
8+
if (index + 1) % 3 != 0 {
9+
output += c;
10+
}
11+
}
12+
return output;
13+
}
14+
}

0 commit comments

Comments
 (0)