Skip to content

Commit

Permalink
Create 1475. Final Prices With a Special Discount in a Shop.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahesh-addagatla authored Dec 18, 2024
1 parent 77e82ee commit 14d42d5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 1475. Final Prices With a Special Discount in a Shop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
public int[] finalPrices(int[] prices) {
Stack<Integer> st = new Stack();
int n=prices.length-1;
for(int i=n ;i>=0;i--){
while(!st.isEmpty() && st.peek()>prices[i]){
st.pop();
}
int discount = st.isEmpty()?0:st.peek();
st.push(prices[i]);
prices[i]-=discount;
}
return prices;
}
}

0 comments on commit 14d42d5

Please sign in to comment.