从零开始的刷LeetCode生活 第26期 261-270
作者:互联网
class Solution {
public:
bool isUgly(int num) {
if(num <= 0) return false;
while(num % 5 == 0)
num /= 5;
while(num % 3 == 0)
num /= 3;
while(num % 2 == 0)
num /= 2;
return num == 1;
}
};
class Solution {
public:
int nthUglyNumber(int n) {
vector<int>q;
q.push_back(1);
int i = 0, j = 0, k = 0;
while(--n)
{
int t = min(q[i] * 2, min(q[j] * 3, q[k] * 5));
q.push_back(t);
if(q[i] * 2 == t) i ++;
if(q[j] * 3 == t) j ++;
if(q[k] * 5 == t) k ++;
}
return q.back();
}
};
class Solution {
public:
int missingNumber(vector<int>& nums) {
int sum = 0;
for(auto x : nums) sum += x;
return (0 + nums.size()) * (nums.size() + 1) / 2 - sum;
}
};
WMXNLFD
发布了121 篇原创文章 · 获赞 33 · 访问量 7274
私信
关注
标签:26,nums,int,sum,back,Solution,270,261,public 来源: https://blog.csdn.net/qq_42549254/article/details/104080085