题目标签: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<Integer> powerfulIntegers(int x, int y, int bound)
{
Set<Integer> 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 题目列表 - LeetCode Questions List

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

LeetCode 970. Powerful Integers (强整数)的更多相关文章

  1. 【LeetCode】Powerful Integers(强整数)

    这道题是LeetCode里的第970道题. 题目描述: 给定两个正整数 x 和 y,如果某一整数等于 x^i + y^j,其中整数 i >= 0 且 j >= 0,那么我们认为该整数是一个 ...

  2. Leetcode970. Powerful Integers强整数

    给定两个非负整数 x 和 y,如果某一整数等于 x^i + y^j,其中整数 i >= 0 且 j >= 0,那么我们认为该整数是一个强整数. 返回值小于或等于 bound 的所有强整数组 ...

  3. Leetcode 970. Powerful Integers

    Brute Force(暴力) class Solution(object): def powerfulIntegers(self, x, y, bound): """ ...

  4. 【Leetcode_easy】970. Powerful Integers

    problem 970. Powerful Integers solution: class Solution { public: vector<int> powerfulIntegers ...

  5. 【LeetCode】970. Powerful Integers 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力搜索 日期 题目地址:https://leetc ...

  6. 【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 ...

  7. 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 ...

  8. [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 ...

  9. Leetcode 970. 强整数

    970. 强整数  显示英文描述 我的提交返回竞赛   用户通过次数223 用户尝试次数258 通过次数231 提交次数801 题目难度Easy 给定两个正整数 x 和 y,如果某一整数等于 x^i ...

随机推荐

  1. C++学习笔记(三)之函数库

    1.标准库函数 begin end begin 返回数组首地址 end   返回数组尾地址 2.const 在声明变量时对变量限制为只读,不允许修改 const int i = 5; 单个const作 ...

  2. Ngnix SSL配置(HTTP、HTTPS兼容)

    一.使用阿里云提供证书 下载aliyun证书for Nginx,解压出两个文件,.pem和.key文件 在nginx安装目录Conf文件夹下新建cert文件夹,拷贝两个密钥文件 二.配置nginx 打 ...

  3. parsley之验证属性设置

    parsley.js添加表单验证功能,直接在html元素中添加对应属性: Name API Description Required #2.0必填 required HTML5 data-parsle ...

  4. UI设计四要素

    信息.样式.布局.交互. +层次: UI所有的工作都可以从这几个方面入手.

  5. CAD得到0层上的所有实体(com接口VB语言)

    主要用到函数说明: IMxDrawSelectionSet::Select 构造选择集.详细说明如下: 参数 说明 [in] MCAD_McSelect Mode 构造选择集方式 [in] VARIA ...

  6. spring用来干什么,解决的问题

    // 1. 实体类 class User{ } //2. dao class  UserDao{ .. 访问db } //3. service class  UserService{ UserDao ...

  7. Android 7.0系统代码调用安装apk时报错FileUriExposedException完美解决

    项目更新遇到问题   Android项目开发中经常遇到下载更新的需求,以前调用系统安装器执行安装操作代码如下: Intent intent = new Intent(); intent.setActi ...

  8. ViewPager与fragment详解链接

    http://blog.csdn.net/harvic880925/article/details/38453725, http://blog.csdn.net/mwj_88/article/deta ...

  9. Android开发技巧一--weight属性实现视图的居中(半)显示

    面试时,一位面试官问到:“如果我想讲按钮居中显示,并且占据其父视图宽度的一半,应该怎么做到呢?”即实现这种效果: 我们使用weightSum属性和layout_weight属性实现这一要求: < ...

  10. mysql运维常用

    一.用户授权 用户授权主要指: 1.可以限制用户访问那些库.表 2.可以限制用户对库.表执行select.create.delete.alter.drop等操作 3.可以限制用户登陆的IP.IP段.或 ...