Skip to content

Commit b3ea3b0

Browse files
solves #2180 Count Integers With Even Digit Sum in java
1 parent 0ee8b5a commit b3ea3b0

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -707,14 +707,14 @@
707707
| 2129 | [Capitalize the Title](https://leetcode.com/problems/capitalize-the-title) | [![Java](assets/java.png)](src/CapitalizeTheTitle.java) | |
708708
| 2133 | [Check if Every Row and Column Contains All Numbers](https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers) | [![Java](assets/java.png)](src/CheckIfEveryRowAndEveryColumnContainAllNumbers.java) | |
709709
| 2138 | [Divide a String Into Groups of Size k](https://leetcode.com/problems/divide-a-string-into-groups-of-size-k) | [![Java](assets/java.png)](src/DivideTheStringIntoGroupsOfSizeK.java) | |
710-
| 2144 | [Minimum Cost of Buying Candies With Discount](https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount) | [![Java](assets/java.png)](src/CountIntegersWithEvenDigitSum.java) | |
710+
| 2144 | [Minimum Cost of Buying Candies With Discount](https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount) | [![Java](assets/java.png)](src/MinimumCostOfBuyingCandiesWithDiscount.java) | |
711711
| 2148 | [Count Elements With Strictly Smaller and Greater Elements](https://leetcode.com/problems/count-elements-with-strictly-smaller-and-greater-elements) | | |
712712
| 2154 | [Keep Multiplying Found Values by Two](https://leetcode.com/problems/keep-multiplying-found-values-by-two) | | |
713713
| 2160 | [Minimum Sum of Four Digit Number After Splitting Digits](https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits) | | |
714714
| 2164 | [Sort Even and Odd Indices Independently](https://leetcode.com/problems/sort-even-and-odd-indices-independently) | | |
715715
| 2169 | [Count Operations to Obtain Zero](https://leetcode.com/problems/count-operations-to-obtain-zero) | | |
716716
| 2176 | [Count Equal and Divisible Pairs in an Array](https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array) | | |
717-
| 2180 | [Count Integers With Even Digit Sum](https://leetcode.com/problems/count-integers-with-even-digit-sum) | | |
717+
| 2180 | [Count Integers With Even Digit Sum](https://leetcode.com/problems/count-integers-with-even-digit-sum) | [![Java](assets/java.png)](src/CountIntegersWithEvenDigitSum.java) | |
718718
| 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix) | | |
719719
| 2190 | [Most Frequent Number Following Key In an Array](https://leetcode.com/problems/most-frequent-number-following-key-in-an-array) | | |
720720
| 2194 | [Cells in a Range on an Excel Sheet](https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet) | | |

Diff for: src/MinimumCostOfBuyingCandiesWithDiscount.java

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount
2+
// T: O(n log(n))
3+
// S: O(log(n))
4+
5+
import java.util.Arrays;
6+
7+
public class MinimumCostOfBuyingCandiesWithDiscount {
8+
public int minimumCost(int[] cost) {
9+
Arrays.sort(cost);
10+
int totalCost = 0;
11+
for (int index = cost.length - 1 ; index >= 0 ; index -= 3) {
12+
totalCost += cost[index] + (index - 1 >= 0 ? cost[index - 1] : 0);
13+
}
14+
return totalCost;
15+
}
16+
}

0 commit comments

Comments
 (0)