Skip to content

Commit e81ab85

Browse files
add 1475
1 parent c364b32 commit e81ab85

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-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+
|1476|[Final Prices With a Special Discount in a Shop](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1476.java) | |Easy|Array|
1112
|1471|[The k Strongest Values in an Array](https://leetcode.com/problems/the-k-strongest-values-in-an-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1471.java) | |Medium|Array, Sort|
1213
|1470|[Shuffle the Array](https://leetcode.com/problems/shuffle-the-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1470.java) | |Easy|Array|
1314
|1466|[Reorder Routes to Make All Paths Lead to the City Zero](https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1466.java) | |Medium|Tree, DFS|
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1475 {
4+
public static class Solution1 {
5+
public int[] finalPrices(int[] prices) {
6+
int[] result = new int[prices.length];
7+
for (int i = 0; i < prices.length; i++) {
8+
boolean foundDiscount = false;
9+
for (int j = i + 1; j < prices.length; j++) {
10+
if (prices[j] <= prices[i]) {
11+
result[i] = prices[i] - prices[j];
12+
foundDiscount = true;
13+
break;
14+
}
15+
}
16+
if (!foundDiscount) {
17+
result[i] = prices[i];
18+
}
19+
}
20+
result[prices.length - 1] = prices[prices.length - 1];
21+
return result;
22+
}
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1475;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertArrayEquals;
8+
9+
public class _1475Test {
10+
private static _1475.Solution1 solution1;
11+
private static int[] prices;
12+
13+
@BeforeClass
14+
public static void setup() {
15+
solution1 = new _1475.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
prices = new int[]{8, 4, 6, 2, 3};
21+
assertArrayEquals(new int[]{4, 2, 4, 2, 3}, solution1.finalPrices(prices));
22+
}
23+
24+
}

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