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. Python实现机器学习算法:AdaBoost算法

    Python程序 ''' 数据集:Mnist 训练集数量:60000(实际使用:10000) 测试集数量:10000(实际使用:1000) 层数:40 ------------------------ ...

  2. skype for business 无法共享桌面、无法传输图片

    以管理员身份运行如下PowerShell命令,清除Skype for Business缓存记录 #以管理员身份运行如下PowerShell命令,清除Skype for Business缓存记录 Sto ...

  3. HBase与列存储

    传统的行存储和(HBase)列存储的区别 1.为什么要按列存储 列式存储(Columnar or column-based)是相对于传统关系型数据库的行式存储(Row-basedstorage)来说的 ...

  4. MySQL中查询时间最大的一条记录

    在项目中要查询用户最近登录的一条记录的 ip 直接写如下 SQL: SELECT ip,MAX(act_time) FROM users_login GROUP BY login_id; 但是这样是取 ...

  5. C++中substr函数的用法

    #include<iostream> #include<string> using namespace std; int main(){ string str("12 ...

  6. Chrome,你这坑人的默认非安全端口

    今天用chrome打开页面的发现一个错误: ERR_UNSAFE_PORT 字面意思是error:不安全端口. 一.什么是默认非安全端口?    每个浏览器出于安全问题,都会禁止一些网络浏览以外的端口 ...

  7. sublime3 mac : Package Control There are no packages available for installation

    如下问题: 查看控制台:点击 ctrl+`打开控制台 发现是因为http://packagecontrol.io/channel_v3.json 获取失败,手动下载channel_v3.json文件, ...

  8. Java SE LinkedList的底层实现

    关于实现链表的底层原理 链表便于增删,不便于查询 package com.littlepage.linkedList; /** * 基于底层实现LinkedList * @author Littlep ...

  9. 项目上有红色感叹号, 一般就是依赖包有问题, remove依赖,重新加载,maven的也行可认删除,自己也会得新加载

    项目上的红色叹号, 要下面提示: "Problems"  里的errors  , 看是什么错误,  一般是由于网络等原因,  依赖没有下载完整,  只有文件名字对了,  内容不全, ...

  10. java重新开始学习

    1.从菜鸟网站开始学习.http://www.runoob.com/java/java-tutorial.html 2. String args[] 与 String[] args 还有一个就是Str ...