970. 强整数

 显示英文描述

 
  • 用户通过次数223
  • 用户尝试次数258
  • 通过次数231
  • 提交次数801
  • 题目难度Easy

给定两个正整数 x 和 y,如果某一整数等于 x^i + y^j,其中整数 i >= 0 且 j >= 0,那么我们认为该整数是一个强整数

返回值小于或等于 bound 的所有强整数组成的列表。

你可以按任何顺序返回答案。在你的回答中,每个值最多出现一次。

示例 1:

输入:x = 2, y = 3, bound = 10
输出:[2,3,4,5,7,9,10]
解释:
2 = 2^0 + 3^0
3 = 2^1 + 3^0
4 = 2^0 + 3^1
5 = 2^1 + 3^1
7 = 2^2 + 3^1
9 = 2^3 + 3^0
10 = 2^0 + 3^2

示例 2:

输入:x = 3, y = 5, bound = 15
输出:[2,4,6,8,10,14]

提示:

  • 1 <= x <= 100
  • 1 <= y <= 100
  • 0 <= bound <= 10^6
class Solution {
public:
vector<int> powerfulIntegers(int x, int y, int bound) {
set<int> jihe;
vector<int> ans;
if(x == &&y == ){
if(bound < ) return ans;
else{
ans.push_back();
return ans;
}
}
if(x == ){
for(int j=;+pow(y,j)<=bound;j++){
jihe.insert(+pow(y,j));
}
}
else{
for(int i=;pow(x,i) <= bound;i++){
if(y == ){if(pow(x,i)+<=bound)jihe.insert(pow(x,i)+);}
else{
for(int j=;pow(x,i)+pow(y,j)<=bound;j++){
jihe.insert(pow(x,i)+pow(y,j));
}
}
}
}
vector<int> res;
set<int>::iterator iter;
for(iter = jihe.begin();iter != jihe.end();iter++){
res.push_back(*iter);
}
return res;
}
};

————主要是第一个数是1比较烦

我真的蠢,看别人的解法,只要加点限制就好了

i = bound if x == 1 else x j = bound if y == 1 else y

class Solution {
public:
vector<int> powerfulIntegers(int x, int y, int bound) {
set<int> ans;
vector<int> res;
for(int i = ; i<=bound; i = i*x){
for(int j= ; j<=bound;j = j*y){
if(i+j <=bound){
ans.insert(i+j);
}
if(y==){
break;
}
}
if( x == ){
break;
}
} for(auto tmp:ans){
res.push_back(tmp);
}
return res;
}
};

——看看别人的,我特么写的是坨屎 啊

Leetcode 970. 强整数的更多相关文章

  1. LeetCode970. 强整数

    问题:970. 强整数 用户通过次数0 用户尝试次数0 通过次数0 提交次数0 题目难度Easy 给定两个非负整数 x 和 y,如果某一整数等于 x^i + y^j,其中整数 i >= 0 且  ...

  2. 【LeetCode】Powerful Integers(强整数)

    这道题是LeetCode里的第970道题. 题目描述: 给定两个正整数 x 和 y,如果某一整数等于 x^i + y^j,其中整数 i >= 0 且 j >= 0,那么我们认为该整数是一个 ...

  3. [Swift]LeetCode970.强整数 | Powerful Integers

    Given two non-negative integers x and y, an integer is powerful if it is equal to x^i + y^j for some ...

  4. leetcode python两整数之和

    # Leetcode 371 两整数之和***### 题目描述 **不使用**运算符 `+` 和 `-` ​​​​​​​,计算两整数 `​​​​​​​a `.`b` ​​​​​​​之和. **示例1: ...

  5. Leetcode970. Powerful Integers强整数

    给定两个非负整数 x 和 y,如果某一整数等于 x^i + y^j,其中整数 i >= 0 且 j >= 0,那么我们认为该整数是一个强整数. 返回值小于或等于 bound 的所有强整数组 ...

  6. LeetCode 970. Powerful Integers (强整数)

    题目标签:HashMap 题目让我们找出所有独一的powerful integers 小于bound的情况下. 把 x^i 看作 a:把 y^j 看作b, 代入for loop,把所有的情况都遍历一遍 ...

  7. [LeetCode] Integer Replacement 整数替换

    Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If ...

  8. Leetcode(力扣) 整数反转

    Leetcode 7.整数反转 给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. 示例: 输入: -123 输出: -321 注意: 假设我们的环境只能存储得下 32 位的有符 ...

  9. python刷LeetCode:7. 整数反转

    难度等级:简单 题目描述: 给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. 示例 1: 输入: 123输出: 321 示例 2: 输入: -123输出: -321示例 3: ...

随机推荐

  1. (转载)Sublime Text 3 快捷键大全

    选择类Ctrl+D 选中光标所占的文本,继续操作则会选中下一个相同的文本.Alt+F3 选中文本按下快捷键,即可一次性选择全部的相同文本进行同时编辑.举个栗子:快速选中并更改所有相同的变量名.函数名等 ...

  2. Unity3D学习笔记(二十八):Editor

    Editor: 对编辑器进行一些拓展开发 关于继承Mono类的扩展开发   特性: [特性]:声明性的标签(类,方法,结构体,变量) 特性只对字段声明有效,后面必须接字段:多个特性,可以修饰一个字段 ...

  3. SQL语句总结2018-11-7

    增加一条数据 insert into table (列字段1,列字段2)values(列1值,列2值) 删除一条数据 delete from table where 列名1=值1 修改一条数据 upd ...

  4. springcloud问题随笔

    http://www.cnblogs.com/EasonJim/p/8085120.html 1.调用其它服务返回could not be queued for execution and no fa ...

  5. sublime配置 sublimecondeintel 分号后不要提示

    https://github.com/SublimeCodeIntel/SublimeCodeIntel/issues/461 Thanks to @catgsmith ,I find a simil ...

  6. 1、Ansible简介及简单安装、使用

    参考Ansible权威指南:https://ansible-tran.readthedocs.io/en/latest/index.html 以下内容学习自马哥教育 Ansible: 运维工作:系统安 ...

  7. 3、Python函数详解(0601)

    回顾: re search,findall,finditer.sub,subn function ()    调用函数 def func_name(arg1,....)   生成函数对象 func_s ...

  8. Leetcode122-Best Time to Buy and Sell Stock II-Easy

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  9. hihoCoder 1339 Dice Possibility(DP)

    http://hihocoder.com/problemset/problem/1339 题意: 求一个骰子扔n次后最后点数相加为m的概率. 思路: f[i][j]表示扔到第i次时总值为j的概率. # ...

  10. <script src="../build/browser.min.js"></script> 是用来里面babel工具把ES6的语法转成ES5

    <!DOCTYPE html> <html> <head> <script src="../build/react.js">< ...