LC 970. 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 integers i >= 0
and j >= 0
.
Return a list of all powerful integers that have value less than or equal to bound
.
You may return the answer in any order. In your answer, each value should occur at most once.
Example 1:
Input: x = 2, y = 3, bound = 10
Output: [2,3,4,5,7,9,10]
Explanation:
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
Example 2:
Input: x = 3, y = 5, bound = 15
Output: [2,4,6,8,10,14]
Note:
1 <= x <= 100
1 <= y <= 100
0 <= bound <= 10^6
Runtime: 9 ms, faster than 52.02% of Java online submissions for Powerful Integers.
class Solution {
public static void init(List<Integer> A, int x, int bound){
if(x == ){
A.add();
return;
}
for(int i=; ; i++){
int tmp = (int) Math.pow(x, i);
if(tmp < bound){
A.add(tmp);
}else break;
}
return ;
}
public List<Integer> powerfulIntegers(int x, int y, int bound) {
List<Integer> arrx = new ArrayList<>();
List<Integer> arry = new ArrayList<>();
init(arrx, x, bound);
init(arry, y, bound);
Set<Integer> s = new HashSet<>();
for(int i=; i<arrx.size(); i++){
for(int j=; j<arry.size(); j++){
if(arrx.get(i) + arry.get(j) <= bound) s.add(arrx.get(i) + arry.get(j));
}
}
List<Integer> ret = new ArrayList<>();
Iterator<Integer> iter = s.iterator();
while(iter.hasNext()){
ret.add(iter.next());
}
return ret;
}
}
LC 970. Powerful Integers的更多相关文章
- 【Leetcode_easy】970. Powerful Integers
problem 970. Powerful Integers solution: class Solution { public: vector<int> powerfulIntegers ...
- LeetCode 970. Powerful Integers (强整数)
题目标签:HashMap 题目让我们找出所有独一的powerful integers 小于bound的情况下. 把 x^i 看作 a:把 y^j 看作b, 代入for loop,把所有的情况都遍历一遍 ...
- 【leetcode】970. Powerful Integers
题目如下: Given two non-negative integers x and y, an integer is powerful if it is equal to x^i + y^j fo ...
- 【LeetCode】970. Powerful Integers 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力搜索 日期 题目地址:https://leetc ...
- Leetcode 970. Powerful Integers
Brute Force(暴力) class Solution(object): def powerfulIntegers(self, x, y, bound): """ ...
- [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 ...
- 118th LeetCode Weekly Contest 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】Powerful Integers(强整数)
这道题是LeetCode里的第970道题. 题目描述: 给定两个正整数 x 和 y,如果某一整数等于 x^i + y^j,其中整数 i >= 0 且 j >= 0,那么我们认为该整数是一个 ...
- LeetCode.970-强大的整数(Powerful Integers)
这是悦乐书的第367次更新,第395篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第229题(顺位题号是970).给定两个正整数x和y,如果对于某些整数i >= 0 ...
随机推荐
- react 预览pdf 转换
function getReader(response){ return new Promise(function(resolve,reject){ response.blob().then( blo ...
- JavaSpring【七、AspectJ】
AspectJ 概念 @AspectJ类似纯Java注解的普通Java类 Spring可以使用AspectJ来作为切入点 AOP在运行时仍是纯SpringAOP,对AspectJ无依赖 配置: 对@A ...
- html图片自定义裁剪大小
该插件后端使用ASP.NET MVC实现图片存储 该插件适用于需要固定显示缩略图片的文章列表! 演示地址:http://hhcf.top:8099/Cropper/Index 源码下载:https:/ ...
- 算法---FaceNet+mtcnn的使用记录
FaceNet+mtcnn---ubutntu系统下的使用记录 @WP20190307 由于先配置了FaceNet算法,中途遇到了点问题,单独又配置了mtcnn进行学习,没有深入,蜻蜓点水.今天,在尝 ...
- java 值传递还是引用传递
首先看一下这篇文章 -- 跳 这篇文章就进行了大致的介绍,以及一些简单的例子,但是还缺少一个关键的例子: public class QQ { public static void main(Strin ...
- Hive的JDBC连接
首相要安装好hive 1.首先修改配置文件文件为hive 路径下的 conf/hive-sit.xml 将内容增加 <property> <name>hive.server2 ...
- php操作kafka
php操作kafka----可以参照网上的安装步骤,先安装ldkafka rdkafka,然乎启动zookeeper和kafka服务器 <?php //$conf = new Rdkafka\P ...
- [jenkins] 启动错误 Failed to start LSB: Jenkins Automation Server.
解决办法见https://blog.csdn.net/qq_34208844/article/details/87865672
- laravel 服务容器的用法
建立一个服务 <?php namespace App\Services; class FooService { public function __construct(){ } public f ...
- xftp传输文件失败
迁移yii项目的时候,需要手动传输runtime文件夹.但是发现总是传输失败,后来得知是因为xftp必须是root用户才能传输成功. 或者把传输的目标文件夹权限修改为777. 修改目标文件夹的属主和属 ...