Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit aa9b319

Browse files
add 2144
1 parent 16f7fdf commit aa9b319

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|2144|[Minimum Cost of Buying Candies With Discount](https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2144.java) ||Easy||
1112
|2139|[Minimum Moves to Reach Target Score](https://leetcode.com/problems/minimum-moves-to-reach-target-score/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2139.java) ||Medium||
1213
|2138|[Divide a String Into Groups of Size k](https://leetcode.com/problems/divide-a-string-into-groups-of-size-k/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2138.java) ||Easy||
1314
|2134|[Minimum Swaps to Group All 1's Together II](https://leetcode.com/problems/minimum-swaps-to-group-all-1s-together-ii/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2134.java) ||Medium||
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.Arrays;
4+
5+
public class _2144 {
6+
public static class Solution1 {
7+
public int minimumCost(int[] cost) {
8+
Arrays.sort(cost);
9+
int ans = 0;
10+
for (int i = cost.length - 1; i >= 0; i--) {
11+
ans += cost[i];
12+
i--;
13+
if (i >= 0) {
14+
ans += cost[i];
15+
}
16+
i--;
17+
}
18+
return ans;
19+
}
20+
}
21+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._2144;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _2144Test {
10+
private static _2144.Solution1 solution1;
11+
private static int[] cost;
12+
private static int expected;
13+
14+
@BeforeClass
15+
public static void setup() {
16+
solution1 = new _2144.Solution1();
17+
}
18+
19+
@Test
20+
public void test1() {
21+
expected = 5;
22+
cost = new int[]{1, 2, 3};
23+
assertEquals(expected, solution1.minimumCost(cost));
24+
}
25+
26+
@Test
27+
public void test2() {
28+
expected = 23;
29+
cost = new int[]{6, 5, 7, 9, 2, 2};
30+
assertEquals(expected, solution1.minimumCost(cost));
31+
}
32+
33+
@Test
34+
public void test3() {
35+
expected = 10;
36+
cost = new int[]{5, 5};
37+
assertEquals(expected, solution1.minimumCost(cost));
38+
}
39+
40+
}

0 commit comments

Comments
 (0)