add: 230502-CN

This commit is contained in:
Eatswap 2023-05-02 09:51:35 +08:00
parent e4093d32fd
commit dbb28499e4
Signed by: Eatswap
GPG Key ID: BE661106A1F3FA0B
3 changed files with 41 additions and 0 deletions

25
cpp/2305/LC230502CN.cpp Normal file
View File

@ -0,0 +1,25 @@
#include <unordered_set>
#include <vector>
class LC230502CN {
public:
static std::vector<int> powerfulIntegers(int, int, int) noexcept;
};
std::vector<int> LC230502CN::powerfulIntegers(int x, int y, int bound) noexcept {
if (bound < 2)
return {};
if (x < y)
std::swap(x, y);
if (x <= 1)
return {2};
std::unordered_set<int> s { 2 };
for (int ix = 1; ix + 1 <= bound; ix *= x) {
s.insert(ix + 1);
if (y <= 1)
continue;
for (int iy = 1; ix + iy <= bound; iy *= y)
s.insert(ix + iy);
}
return {s.begin(), s.end()};
}

View File

@ -14,4 +14,10 @@ public:
static double average(const std::vector<int>&) noexcept;
};
class LC230502CN {
public:
static std::vector<int> powerfulIntegers(int, int, int) noexcept;
};
#endif //LEETCODE_CPP_DEFS_H

View File

@ -1,9 +1,19 @@
#include <iostream>
#include <ostream>
#include <vector>
#include "defs.h"
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& x) noexcept {
for (auto&& i : x)
os << i << ", ";
return os;
}
int main() {
std::cout << LC230501::average({1, 2, 3, 4}) << std::endl;
std::cout << LC230501CN::numOfMinutes(1, 0, {-1}, {0}) << std::endl;
std::cout << LC230502CN::powerfulIntegers(2, 1, 10) << std::endl;
return 0;
}