Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaa9b319

Browse files
add 2144
1 parent16f7fdf commitaa9b319

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+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.Arrays;
4+
5+
publicclass_2144 {
6+
publicstaticclassSolution1 {
7+
publicintminimumCost(int[]cost) {
8+
Arrays.sort(cost);
9+
intans =0;
10+
for (inti =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+
returnans;
19+
}
20+
}
21+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._2144;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_2144Test {
10+
privatestatic_2144.Solution1solution1;
11+
privatestaticint[]cost;
12+
privatestaticintexpected;
13+
14+
@BeforeClass
15+
publicstaticvoidsetup() {
16+
solution1 =new_2144.Solution1();
17+
}
18+
19+
@Test
20+
publicvoidtest1() {
21+
expected =5;
22+
cost =newint[]{1,2,3};
23+
assertEquals(expected,solution1.minimumCost(cost));
24+
}
25+
26+
@Test
27+
publicvoidtest2() {
28+
expected =23;
29+
cost =newint[]{6,5,7,9,2,2};
30+
assertEquals(expected,solution1.minimumCost(cost));
31+
}
32+
33+
@Test
34+
publicvoidtest3() {
35+
expected =10;
36+
cost =newint[]{5,5};
37+
assertEquals(expected,solution1.minimumCost(cost));
38+
}
39+
40+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp