add: 230502-CN
This commit is contained in:
parent
e4093d32fd
commit
dbb28499e4
|
|
@ -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()};
|
||||||
|
}
|
||||||
|
|
@ -14,4 +14,10 @@ public:
|
||||||
static double average(const std::vector<int>&) noexcept;
|
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
|
#endif //LEETCODE_CPP_DEFS_H
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,19 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "defs.h"
|
#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() {
|
int main() {
|
||||||
std::cout << LC230501::average({1, 2, 3, 4}) << std::endl;
|
std::cout << LC230501::average({1, 2, 3, 4}) << std::endl;
|
||||||
std::cout << LC230501CN::numOfMinutes(1, 0, {-1}, {0}) << std::endl;
|
std::cout << LC230501CN::numOfMinutes(1, 0, {-1}, {0}) << std::endl;
|
||||||
|
std::cout << LC230502CN::powerfulIntegers(2, 1, 10) << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue