Sorting - Mark and Toys [Easy]
用有限的錢, 買最多玩具
Sample Input
7 50
1 12 5 111 200 1000 10
Sample Output
4
Explanation
He can buy only toys at most. These toys have the following prices: .
static int maximumToys(int[] prices, int k) {
Arrays.sort(prices);
for(int i = 0; i < prices.length; i++){
k-=prices[i];
if(k < 0) return i;
}
return prices.length;
}
留言
張貼留言