Skip to content

Commit 138d00d

Browse files
add 2288
1 parent 6264e84 commit 138d00d

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-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+
| 2288 |[Apply Discount to Prices](https://leetcode.com/problems/apply-discount-to-prices/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2288.java) || Medium ||
1112
| 2284 |[Sender With Largest Word Count](https://leetcode.com/problems/sender-with-largest-word-count/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2284.java) || Medium ||
1213
| 2283 |[Check if Number Has Equal Digit Count and Digit Value](https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2283.java) || Easy ||
1314
| 2279 |[Maximum Bags With Full Capacity of Rocks](https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2279.java) || Medium ||
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _2288 {
4+
public static class Solution1 {
5+
public String discountPrices(String sentence, int discount) {
6+
StringBuilder sb = new StringBuilder();
7+
String[] words = sentence.split(" ");
8+
for (String word : words) {
9+
if (word.charAt(0) == '$') {
10+
try {
11+
long num = Long.parseLong(word.substring(1));
12+
double newNum = Math.round(num * (1 - ((discount * 1.0) / 100)) * 100.00) / 100.00;
13+
sb.append("$");
14+
sb.append(String.format("%.2f", newNum));
15+
} catch (Exception e) {
16+
sb.append(word);
17+
}
18+
} else {
19+
sb.append(word);
20+
}
21+
sb.append(" ");
22+
}
23+
return sb.substring(0, sb.length() - 1);
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy