题目标签: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. python自动化--语言基础一数据类型及类型转换

    Python中核心的数据类型有哪些?变量(数字.字符串.元组.列表.字典) 什么是数据的不可变性?哪些数据类型具有不可变性数据的不可变是指数据不可更改,比如: a = () #定义元组 #a[]= # ...

  2. ElasticSearch 安装使用

    安装: 1.下载ElasticSearch.解压到相关文件夹 2.运行elasticsearch.bat,启动程序 3.在浏览器输入:http://localhost:9200/,显示相关Es内容即安 ...

  3. [Windows Server 2012] SQL Server 备份和还原方法

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:SQL S ...

  4. BZOJ 3884: 上帝与集合的正确用法 扩展欧拉定理 + 快速幂

    Code: #include<bits/stdc++.h> #define maxn 10000004 #define ll long long using namespace std; ...

  5. cstring to utf8

    char* UnicodeToUtf8(CString unicode) { int len; len = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)unico ...

  6. ThinkPHP---案例2--职员管理功能

    [一]准备工作 (1)创建菜单,修改跳转路径 <li> <a href="javascript:;" class="workerManage" ...

  7. css 实现鼠标滑过流光效果

    来划我啊 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...

  8. Vim常用快捷键--正常的学习曲线

    vim可能对于初学者不太友好,学习曲线有点陡,特此整理了较为平滑的学习曲线的学习快捷键的方式,包含最常用的快捷键,让初学者领悟vim的优点,想要进阶学习请查找其它更好的教程 正常模式:可以使用快捷键命 ...

  9. Python supprocess模块

    当我们需要调用系统的命令的时候,最先考虑的os模块.用os.system()和os.popen()来进行操作.但是这两个命令过于简单,不能完成一些复杂的操作,如给运行的命令提供输入或者读取命令的输出, ...

  10. Jet --theory

    (FIG. 6. A caricature of turbulent jet and the entrainment., Jimmy, 2012) Ref: Jimmy Philip, Phys. F ...