From 14d42d5d38bca5b9a2837dd2ac7f6ab724814aeb Mon Sep 17 00:00:00 2001 From: MAHESH ADDAGATLA <158994925+Mahesh-addagatla@users.noreply.github.com> Date: Wed, 18 Dec 2024 22:20:20 +0530 Subject: [PATCH] Create 1475. Final Prices With a Special Discount in a Shop.java --- ... Prices With a Special Discount in a Shop.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 1475. Final Prices With a Special Discount in a Shop.java diff --git a/1475. Final Prices With a Special Discount in a Shop.java b/1475. Final Prices With a Special Discount in a Shop.java new file mode 100644 index 0000000..8ccfa1b --- /dev/null +++ b/1475. Final Prices With a Special Discount in a Shop.java @@ -0,0 +1,15 @@ +class Solution { + public int[] finalPrices(int[] prices) { + Stack 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; + } +}