Final Prices With a Special Discount in a Shop
给一个数组, 返回每个数与其后边最近的比他大的数的差.
class Solution {
public int[] finalPrices(int[] prices) {
int n = prices.length;
int[] res = new int[n];
for(int i = n - 1; i >= 0; i--) {
res[i] = prices[i];
for(int j = i + 1; j < n; j++) {
if(prices[j] <= res[i]){
res[i] -= prices[j];
break;
}
}
}
return res;
}
}