leetcode 970.强整数
给定两个正整数 x 和 y,如果某一整数等于 x^i + y^j,其中整数 i >= 0 且 j >= 0,那么我们认为该整数是一个强整数。
返回值小于或等于 bound 的所有强整数组成的列表。
你可以按任何顺序返回答案。在你的回答中,每个值最多出现一次。
提示:
- 1 <= x <= 100
- 1 <= y <= 100
- 0 <= bound <= 10^6
思路:
- i和j的取值范围
- 开始先取bound/_ 作为 max_ - max_的取值优劣直接影响进程的运行时间
- 在循环内判断,若i或j等于0情况下,sum大于bound,更新max_ - max_一开始的取值,有可能不能取到0(当x或y比bound小时)
- so,加一层判断,max_>0?max_:0; - x或y中,若有等于1的情况,max_将失去意义
- 加一个判断,if ==1, max=0 - 输出的结果不能包含重复值
- 利用set的数据插入特性,在输出时转为vector< int >即可。 - sum的数据范围可能过大
- 采用long型
class Solution {
public:
vector<int> powerfulIntegers(int x, int y, int bound) {
set<int> re;
int maxi=bound/x>0?bound/x:0;
int maxj=bound/y>0?bound<