970. 强整数

 显示英文描述

 
  • 用户通过次数223
  • 用户尝试次数258
  • 通过次数231
  • 提交次数801
  • 题目难度Easy

给定两个正整数 x 和 y,如果某一整数等于 x^i + y^j,其中整数 i >= 0 且 j >= 0,那么我们认为该整数是一个强整数

返回值小于或等于 bound 的所有强整数组成的列表。

你可以按任何顺序返回答案。在你的回答中,每个值最多出现一次。

示例 1:

输入:x = 2, y = 3, bound = 10
输出:[2,3,4,5,7,9,10]
解释:
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

示例 2:

输入:x = 3, y = 5, bound = 15
输出:[2,4,6,8,10,14]

提示:

  • 1 <= x <= 100
  • 1 <= y <= 100
  • 0 <= bound <= 10^6
class Solution {
public:
vector<int> powerfulIntegers(int x, int y, int bound) {
set<int> jihe;
vector<int> ans;
if(x == &&y == ){
if(bound < ) return ans;
else{
ans.push_back();
return ans;
}
}
if(x == ){
for(int j=;+pow(y,j)<=bound;j++){
jihe.insert(+pow(y,j));
}
}
else{
for(int i=;pow(x,i) <= bound;i++){
if(y == ){if(pow(x,i)+<=bound)jihe.insert(pow(x,i)+);}
else{
for(int j=;pow(x,i)+pow(y,j)<=bound;j++){
jihe.insert(pow(x,i)+pow(y,j));
}
}
}
}
vector<int> res;
set<int>::iterator iter;
for(iter = jihe.begin();iter != jihe.end();iter++){
res.push_back(*iter);
}
return res;
}
};

————主要是第一个数是1比较烦

我真的蠢,看别人的解法,只要加点限制就好了

i = bound if x == 1 else x j = bound if y == 1 else y

class Solution {
public:
vector<int> powerfulIntegers(int x, int y, int bound) {
set<int> ans;
vector<int> res;
for(int i = ; i<=bound; i = i*x){
for(int j= ; j<=bound;j = j*y){
if(i+j <=bound){
ans.insert(i+j);
}
if(y==){
break;
}
}
if( x == ){
break;
}
} for(auto tmp:ans){
res.push_back(tmp);
}
return res;
}
};

——看看别人的,我特么写的是坨屎 啊

Leetcode 970. 强整数的更多相关文章

  1. LeetCode970. 强整数

    问题:970. 强整数 用户通过次数0 用户尝试次数0 通过次数0 提交次数0 题目难度Easy 给定两个非负整数 x 和 y,如果某一整数等于 x^i + y^j,其中整数 i >= 0 且  ...

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

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

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

  4. leetcode python两整数之和

    # Leetcode 371 两整数之和***### 题目描述 **不使用**运算符 `+` 和 `-` ​​​​​​​,计算两整数 `​​​​​​​a `.`b` ​​​​​​​之和. **示例1: ...

  5. Leetcode970. Powerful Integers强整数

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

  6. LeetCode 970. Powerful Integers (强整数)

    题目标签:HashMap 题目让我们找出所有独一的powerful integers 小于bound的情况下. 把 x^i 看作 a:把 y^j 看作b, 代入for loop,把所有的情况都遍历一遍 ...

  7. [LeetCode] Integer Replacement 整数替换

    Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If ...

  8. Leetcode(力扣) 整数反转

    Leetcode 7.整数反转 给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. 示例: 输入: -123 输出: -321 注意: 假设我们的环境只能存储得下 32 位的有符 ...

  9. python刷LeetCode:7. 整数反转

    难度等级:简单 题目描述: 给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. 示例 1: 输入: 123输出: 321 示例 2: 输入: -123输出: -321示例 3: ...

随机推荐

  1. 第五个神奇的电梯(代码抢先看<1>)

    关于一些自认为比较独特的设计思路,也不知道是好还是坏,放在这里让大家一起看一下. 关于mian函数:因为采用了注册机制所以主函数比较简单. #include "stdafx.h" ...

  2. 【ASP.NET】 MVC下拉框联动

    这个case主要是我在做项目的时候遇到一个需要根据input控件输入的内容,动态填充dropdown list中的内容, 实现二者联动的需求.在搜索了一些资源后,这篇博客解决了我的问题,所以记录并转载 ...

  3. Docker Engine SDKs and API 的开发2

    Examples using the Docker Engine SDKs and Docker API After you install Docker, you can install the G ...

  4. Kubernetes工作流之Pods二

    Init Containers This feature has exited beta in 1.6. Init Containers can be specified in the PodSpec ...

  5. 【转载】常用 Java 静态代码分析工具的分析与比较

    摘自:http://www.oschina.net/question/129540_23043常用 Java 静态代码分析工具的分析与比较 简介: 本文首先介绍了静态代码分析的基本概念及主要技术,随后 ...

  6. POJ 2718 Smallest Difference(最小差)

     Smallest Difference(最小差) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 Given a numb ...

  7. js 字符串加密解密

    Welcome to jzzy.com

  8. Python学习 day04打卡

    今天学习的主要内容: 一,列表 1,列表的介绍 列表是python的基础数据类型之一,其他编程语音也有类似的数据类型.例如:JS 中的数组Java中的数组等等. 它是以[]括起来,每个元素用',隔开而 ...

  9. linux 基本命令2(12月27日笔记)

    1.ifconfig 作用:用于操作网卡相关的指令 简单语法:#ifconfig      (获取网卡信息)   2.reboot 作用:重新启动计算机 语法1:#reboot             ...

  10. go 获取网址html 源码

    // Sample program to show how to write a simple version of curl using // the io.Reader and io.Writer ...