Leetcode 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. 强整数的更多相关文章
- LeetCode970. 强整数
问题:970. 强整数 用户通过次数0 用户尝试次数0 通过次数0 提交次数0 题目难度Easy 给定两个非负整数 x 和 y,如果某一整数等于 x^i + y^j,其中整数 i >= 0 且 ...
- 【LeetCode】Powerful Integers(强整数)
这道题是LeetCode里的第970道题. 题目描述: 给定两个正整数 x 和 y,如果某一整数等于 x^i + y^j,其中整数 i >= 0 且 j >= 0,那么我们认为该整数是一个 ...
- [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 ...
- leetcode python两整数之和
# Leetcode 371 两整数之和***### 题目描述 **不使用**运算符 `+` 和 `-` ,计算两整数 `a `.`b` 之和. **示例1: ...
- Leetcode970. Powerful Integers强整数
给定两个非负整数 x 和 y,如果某一整数等于 x^i + y^j,其中整数 i >= 0 且 j >= 0,那么我们认为该整数是一个强整数. 返回值小于或等于 bound 的所有强整数组 ...
- LeetCode 970. Powerful Integers (强整数)
题目标签:HashMap 题目让我们找出所有独一的powerful integers 小于bound的情况下. 把 x^i 看作 a:把 y^j 看作b, 代入for loop,把所有的情况都遍历一遍 ...
- [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 ...
- Leetcode(力扣) 整数反转
Leetcode 7.整数反转 给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. 示例: 输入: -123 输出: -321 注意: 假设我们的环境只能存储得下 32 位的有符 ...
- python刷LeetCode:7. 整数反转
难度等级:简单 题目描述: 给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. 示例 1: 输入: 123输出: 321 示例 2: 输入: -123输出: -321示例 3: ...
随机推荐
- 并发学习一、MPI初步认识
学习参考地址:https://www.jianshu.com/p/2fd31665e816 编程使用的vs2015 社区版本(个人感觉比Vc6.0的丑界面看起来舒服多了) MPI基本函数 MPI调用借 ...
- Google advertiser api开发概述——部分失败
部分失败 某些 AdWords 服务允许您请求执行有效操作,而对失败的操作返回错误.此功能(称为部分失败)允许您在结束时单独处理失败的操作. 技术细节 要使用此功能,您需要设置此可选的 SOAP 标头 ...
- pyqt笔记2 布局管理
https://zhuanlan.zhihu.com/p/28559136 绝对布局 相关方法setGeometry().move() 箱式布局 QHBoxLayout和QVBoxLayout是基本的 ...
- border:none和border:0的区别
C:当定义border:none时,表示无边框样式,浏览器并不会对边框进行渲染,也就没有实际的宽度: D:定义边框时,除了设置宽度外,还必须设置边框的样式才能显示出来. border:0;浏 ...
- C#解析html文档类库HtmlAgilityPack下载地址
新:http://html-agility-pack.net/?z=codeplex 原:http://htmlagilitypack.codeplex.com/
- VirtualBox安装Centos6.8出现——E_INVALIDARG (0x80070057)
VirtualBox使用已有的虚拟硬盘出错: 问题描述:UUID已经存在 Cannot register the hard disk 'E:\system_iso\centos6.8.vdi' {05 ...
- C#引用出错
今天有朋友问我为什么自己引用了配置文件,但是还不能使用配置文件呢? 之后我查看他的项目,后来发现如下问题,并且总结引用文件流程如下: 引用文件的完整程序如下: 用配置文件举例 项目中的引用右击,然后点 ...
- img 下方的4px像素问题
问题:在一个div块里面放了一个图片,图片下面有内容,可以不管怎么调试,在火狐浏览器,IE6下.图片img底部多出了4个像素 解决:img样式中 vertical-align: top/middl ...
- Given d and e, factorize N to attack RSA
题目如下: RSA算法的使用一般要求每个不同的用户有一个独立的模数N.有天,Bob脑洞大开,认为似乎没有必要这样做.只需要一个模数N,然后给不同的用户分发不同的e和d就好了.可惜这种做法有严重的安全漏 ...
- POI导出时写一份到ftp服务器,一份下载给客户端
导语: 昨天接到项目经理这么一个需求,让我在POI导出Excel的时候写一份到我之前搭建的ftp服务器上.所以就有了这篇博客首先我们来分析下之前的业务逻辑:我们创建并构造了一个workbook,然后构 ...