forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1475.java
24 lines (23 loc) · 807 Bytes
/
_1475.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.fishercoder.solutions;
public class _1475 {
public static class Solution1 {
public int[] finalPrices(int[] prices) {
int[] result = new int[prices.length];
for (int i = 0; i < prices.length; i++) {
boolean foundDiscount = false;
for (int j = i + 1; j < prices.length; j++) {
if (prices[j] <= prices[i]) {
result[i] = prices[i] - prices[j];
foundDiscount = true;
break;
}
}
if (!foundDiscount) {
result[i] = prices[i];
}
}
result[prices.length - 1] = prices[prices.length - 1];
return result;
}
}
}