2021-05-03 不积跬步无以至千里
Leetcode
1475. Final Prices With a Special Discount in a Shop
Given the array prices where prices[i] is the price of the ith item in a shop. There is a special discount for items in the shop, if you buy the ith item, then you will receive a discount equivalent to prices[j] where j is the minimum index such that j > i and prices[j] <= prices[i], otherwise, you will not receive any discount at all.
Return an array where the ith element is the final price you will pay for the ith item of the shop considering the special discount.
public class Solution {
public int[] FinalPrices(int[] prices) {
int[] ret= prices;
int len = prices.Length;
for (int i=0;i<len-1;i++)
{
for(int j=i+1;j<len;j++)
{
if (prices[j] <= prices[i])
{
ret[i] =ret[i]- prices[j];
break;
}
}
}
return ret;
}
}
1万+



被折叠的 条评论
为什么被折叠?



