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 < 0return i;
          }
         return prices.length;


    }


留言

這個網誌中的熱門文章

考績被打差了 輕率離職會更傷

Arrays - DS (Reverse array) [Easy]

WireMock