Guest User

Untitled

a guest
Dec 14th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. class Solution {
  2. public:
  3. int minPatches(vector<int>& nums, int n) {
  4. if(n < 1)return 0;
  5. int count = 0, len = nums.size(), i = 0;
  6. long hi = 0;
  7. while(hi < n)
  8. {
  9. if(i >= len || nums[i] > hi + 1)
  10. {
  11. ++count;
  12. hi = 2 * hi + 1;
  13. }
  14. else
  15. {
  16. hi = nums[i] + hi;
  17. ++i;
  18. }
  19. }
  20. return count;
  21. }
  22. };
Add Comment
Please, Sign In to add comment