[LeetCode 278,283] [simply] the first version of error / zero mobile

278. The first wrong version
topic Link

// Forward declaration of isBadVersion API.
bool isBadVersion(int version);

class Solution {
public:
    typedef long long LL;
    int firstBadVersion(int n) {
        LL l = 1, r = n, m;
        while(l<r){
            m = (l + r)>>1;
            if(isBadVersion(m))r = m;
            else l = m + 1;
        }
        return r;
    }
};

283. Mobile Zero
topic Link

class Solution {
public:
    void moveZeroes(vector<int>& nums) {
        ios::sync_with_stdio(0);cin.tie(0);
        int siz = nums.size(), st = -1, ed = 0;
        while(++st<siz)if(nums[st])swap(nums[st],nums[ed++]);
    }
};
Published 104 original articles · won praise 13 · views 20000 +

Guess you like

Origin blog.csdn.net/IDrandom/article/details/104414317