[LeetCode 278,283][简单]第一个错误的版本/移动零
作者:互联网
278.第一个错误的版本
题目链接
// 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.移动零
题目链接
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++]);
}
};
IDrandom
发布了104 篇原创文章 · 获赞 13 · 访问量 2万+
私信
关注
标签:int,LL,isBadVersion,long,278,283,LeetCode 来源: https://blog.csdn.net/IDrandom/article/details/104414317