LeetCode Patching Array All In One

xgqfrms發表於2024-06-18

LeetCode Patching Array All In One

  1. Patching Array

solution

function minPatches(nums: number[], n: number): number {
  let patch = 1;
  let count = 0;
  let i = 0;
  while (patch <= n) {
    if (nums[i] <= patch && i < nums.length) {
      patch += nums[i];
      i++;
    } else {
      patch += patch;
      count++;
    }
  }
  return count;
};

https://leetcode.com/problems/patching-array/description/?envType=daily-question&envId=2024-06-16

demos


image

(🐞 反爬蟲測試!打擊盜版⚠️)如果你看到這個資訊, 說明這是一篇剽竊的文章,請訪問 https://www.cnblogs.com/xgqfrms/ 檢視原創文章!

refs



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 釋出文章使用:只允許註冊使用者才可以訪問!

原創文章,版權所有©️xgqfrms, 禁止轉載 🈲️,侵權必究⚠️!


相關文章