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 <= 1001 <= y <= 1000 <= 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 ...
随机推荐
- MySQL时间类型及获取、展示处理
MySQL时间格式 mysql所支持的日期时间类型有:DATETIME. TIMESTAMP.DATE.TIME.YEAR. 几种类型比较如下: 日期时间类型 占用空间 日期格式 最小值 最大值 零值 ...
- 【Distributed】大型网站高并发和高可用
一.DNS域名解析 二.大型网站系统应有的特点 三.网站架构演变过程 3.1 传统架构 3.2 分布式架构 3.3 SOA架构 3.4 微服务架构 四.高并发设计原则 4.1 拆分系统 4.2 服务化 ...
- 本地套接字-本地socket
本地套接字简单应用场景 一 #服务端--简单 import socket import os a='sock_file' if os.path.exists(a): os.remove(a) s=so ...
- 移动端设备管理平台 atx server2实践
目录 1.需求背景 2.初步调研 2.1.云测试平台 2.2.开源工具 2.3.VNC 2.4.企业内部自研云测试平台 3.ATX Server安装 依赖环境 安装rethinkdb 安装atx se ...
- deep_learning_学习资料
TensorFlow的55个经典案例:https://blog.csdn.net/xzy_thu/article/details/76220654 吴恩达机器学习: 1.序列学习:https://mo ...
- linux上网时断时续问题
[问题描述]打开百度比较慢:登录远程服务器操作一会儿就断了 [问题环境]ip自动获取 [问题分析]自己的ip地址被人占用了 [问题解决]1)重新手动配置一个新的ip 2)释放原来的ip,重新自动 ...
- web开发:Bootstrap应用及内存管理
一.栅格系统 二.移动端适配 三.栅格系统案例 四.表格 五.表单 六.循环应用 一.栅格系统 <!DOCTYPE html> <html> <head> < ...
- Hadoop_32_HDFS高可用机制
1.高可靠概念 HA(High Available):高可用性集群,是保证业务连续性的有效解决方案,一般有两个或两个以上的节点,且分为活动 节点及备用节点 2.Hadoop的HA运作机制: :正式引入 ...
- vim文本编辑及文件查找应用2
vim编辑器: vim末行模式: 内建的命令行接口 (1)地址定界 :start_pos[,end_pos] #:特定的第#行,例如5即第5行 .:当前行 .,+#:当前行,加#行的行范围 $:最后一 ...
- centos7支持exfat
centos7支持exfat https://blog.csdn.net/shile/article/details/52202030 sudo rpm -Uvh http://li.nux.ro/d ...