题目标签: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. JNDI链接SQLServer数据库步骤

    1.配置context.xml文件 在我们的WebRoot目录下,就是和WEB-INF同级的目录下,新建一个META-INF的目录(假如不存在),在该目录下创建一个context.xml文件,并且在c ...

  2. AMH V4.5 – 基于AMH4.2的第三方开发版

    AMH V4.5[基于AMH4.2第三方开发版]重新部署了一次安装脚本,修改一系列BUG,已完美支持CENTOS7,树莓派,Fedora,Aliyun,Amazon,debian,Ubuntu,Ras ...

  3. swift 工作日志

    开发问题汇总: tableview.register(CEImpWalletHomeCell.self, forCellReuseIdentifier: "cell") var c ...

  4. vue基础---Class 与 Style 绑定

    [一]绑定HTML Class (1)对象语法 ①普通绑定class <div id="area" v-bind:class="className"> ...

  5. 第三节:执行一些EF的增删改查

    针对两表操作 一丶增加 #region 05-增加操作 /// <summary> /// 05-增加操作 /// </summary> /// <param name= ...

  6. 【转】Go语言入门教程(一)Linux下安装Go

    说明 系统是Ubuntu. 关于安装 下载安装包 当前官方下载地址是https://golang.org/dl/,如果不能访问,请自行FQ,FQ是技术工作者的必备技能. 安装 tar -xzvf go ...

  7. 学习笔记7——使用Scanner获取键盘输入

    使用Scanner类可以很方面地获取用户的键盘输入,Scanner是一个基于正则表达式的文本扫描器,它可以从文件.输入流.字符串中解析出基本类型值和字符串值.Scanner类提供了多个构造器,不同的构 ...

  8. 面向对象程序设计--Java语言第二周编程题:有秒计时的数字时钟

    有秒计时的数字时钟 题目内容: 这一周的编程题是需要你在课程所给的时钟程序的基础上修改而成.但是我们并不直接给你时钟程序的代码,请根据视频自己输入时钟程序的Display和Clock类的代码,然后来做 ...

  9. linux网络编程——域名转换 gethostbyname与gethostbyaddr

    域名转换 #include <netdb.h> struct hostent *gethostbyname(const char *name); 参数: name: 执行主机名的指针 返回 ...

  10. Linux---文件目录管理

    1. Linux文件目录架构 Linux的目录结构与win的目录有很大不同,首先,没有盘符的概念:然后Linux使用斜杠/标识目录,Linux首先建立一个根目录,然后将其他文件系统挂载到这个目录下. ...