0
点赞
收藏
分享

微信扫一扫

Java进阶篇之重写与重载的概念及区别

zibianqu 2024-08-13 阅读 41

题目:

题解:

class Solution {
public:
    int minPatches(vector<int>& nums, int n) {
        int patches = 0;
        long long x = 1;
        int length = nums.size(), index = 0;
        while (x <= n) {
            if (index < length && nums[index] <= x) {
                x += nums[index];
                index++;
            } else {
                x <<= 1;
                patches++;
            }
        }
        return patches;
    }
};
举报

相关推荐

0 条评论