当前位置:   article > 正文

C语言 | Leetcode C语言题解之第330题按要求补齐数组

C语言 | Leetcode C语言题解之第330题按要求补齐数组

题目:

题解:

  1. int minPatches(int* nums, int numsSize, int n) {
  2. int patches = 0;
  3. long long x = 1;
  4. int index = 0;
  5. while (x <= n) {
  6. if (index < numsSize && nums[index] <= x) {
  7. x += nums[index];
  8. index++;
  9. } else {
  10. x <<= 1;
  11. patches++;
  12. }
  13. }
  14. return patches;
  15. }
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号