leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2952.cpp (440B)


0 class Solution { 1 public: 2 int minimumAddedCoins(vector<int> &coins, int target) const { 3 int res = 0, get = 0; 4 5 sort(begin(coins), end(coins)); 6 for (int i = 0; i < size(coins) && get < target; i++) { 7 while (get + 1 < coins[i]) 8 get += get + 1, res++; 9 get += coins[i]; 10 } 11 12 while (get < target) 13 get += get + 1, res++; 14 15 return res; 16 } 17 };