博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode 970. Powerful Integers (强整数)
阅读量:4618 次
发布时间:2019-06-09

本文共 999 字,大约阅读时间需要 3 分钟。

题目标签:HashMap

  题目让我们找出所有独一的powerful integers 小于bound的情况下。

  把 x^i 看作 a;把 y^j 看作b, 代入for loop,把所有的情况都遍历一遍。

  参考的这种方法,用for loop 写的比较简洁易懂。

  具体看code。

 

Java Solution:

Runtime: 4 ms, faster than 99.85% 

Memory Usage: 37.5 MB, less than 7.69%

完成日期:03/13/2019

关键点:把 x^i 看作 a;把 y^j 看作b, 代入for loop

class Solution {    public List
powerfulIntegers(int x, int y, int bound) { Set
result = new HashSet<>(); for(int a = 1; a < bound; a *= x) { for(int b = 1; a + b <= bound; b *= y) { result.add(a + b); if(y == 1) break; } if(x == 1) break; } return new ArrayList<>(result); }}

参考资料:https://leetcode.com/problems/powerful-integers/discuss/214197/Java-straightforward-try-all-combinations

LeetCode 题目列表 - 

题目来源:https://leetcode.com/

转载于:https://www.cnblogs.com/jimmycheng/p/10550004.html

你可能感兴趣的文章
python的沙盒环境--virtualenv
查看>>
软件自动化测试——入门、进阶与实战
查看>>
BZOJ1878 [SDOI2009]HH的项链 树状数组 或 莫队
查看>>
BZOJ3675 [Apio2014]序列分割 动态规划 斜率优化
查看>>
2016.10.24 继续学习
查看>>
产品功能对标 - 服务授权管理
查看>>
各地IT薪资待遇讨论
查看>>
splay入门
查看>>
带CookieContainer进行post
查看>>
C语言学习笔记--字符串
查看>>
CSS-上下文选择器
查看>>
ionic repeat 重复最后一个时要执行某个函数
查看>>
1.初识代码审计-基础
查看>>
[Vue-rx] Stream an API using RxJS into a Vue.js Template
查看>>
解决VC几个编译问题的方法——好用
查看>>
SPOJ #11 Factorial
查看>>
City Upgrades
查看>>
“人少也能办大事”---K2 BPM老客户交流会
查看>>
关于七牛进行图片添加文字水印操作小计
查看>>
DataSource数据库的使用
查看>>