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. c# 重试机制

    protected async Task<T> TryOperation<T>(int maxRetryCount,Func<Task<T>> func ...

  2. SPOJ 694 Distinct Substrings(不相同子串个数)

    https://vjudge.net/problem/SPOJ-DISUBSTR 题意: 给定一个字符串,求不相同的子串的个数. 思路: #include<iostream> #inclu ...

  3. 奇异分解(SVD)

    奇异分解 假设C是m×n矩阵,U是m×m矩阵,其中U的列为 的正交特征向量,V为n×n矩阵,其中V的列为 的正交特征向量,再假设r为C矩阵的秩,则存在奇异值分解: 其中和的特征值相同,为 ,且. 是m ...

  4. 总结react native 事件机制

    React 事件机制 一个组件的所有事件会使用统一的事件监听器,绑定到组件的最外层,那么如何使用? bind方法,绑定并且可以传递参数 <TouchableOpacity onPress={th ...

  5. 利用React Native 从0到1 开发一款兼容IOS和android的APP(仿造京东)

    最近有一部电视剧叫做<微微一笑很傻逼>里面有个男猪脚,人们都叫他大神~我觉得吧~大神是相对的~所以~啥事都得谦虚! 好了 今天介绍的是如何从0到1利用React Native开发一款兼容I ...

  6. C# 整理DotNetBar中SuperGridControl的一些基础属性

    //控制表格只能选中单行 superGridControl1.PrimaryGrid.MultiSelect = false; superGridControl1.PrimaryGrid.Initia ...

  7. CentOS7 使用firewalld打开关闭防火墙以及端口

    1.firewalld的基本使用 启动 systemctl start firewalld 关闭 systemctl stop firewalld 查看状态 systemctl status fire ...

  8. Mongodb 创建管理员帐号与普通帐号

    数据库操作权限 readAnyDatabase 任何数据库的只读权限 userAdminAnyDatabase 任何数据库的读写权限 userAdminAnyDatabase 任何数据库用户的管理权限 ...

  9. Python 注释,类,属性,方法,继承

    # coding=utf-8 支持中文 """ 多行注释 声明鸟类 """ class Bird(object): have_feather ...

  10. eclipse打开失败

    以前eclipse运行好好的,某一次运行启动不了,一直图标那里转圈,不能启动, 运行eclipsec.exe后,查看发现出现以下错误 SLF4J: Class path contains multip ...