【Leetcode_easy】970. Powerful Integers

problem

970. Powerful Integers

solution:

class Solution {
public:
    vector<int> powerfulIntegers(int x, int y, int bound) {
        unordered_set<int> tmp;
        for(int a=1; a<bound; a*=x)//
        {
            for(int b=1; a+b<=bound; b*=y)
            {
                tmp.insert(a+b);//
                if(y==1) break;//
            }
            if(x==1) break;
        }
        return vector<int>(tmp.begin(), tmp.end());
    }

};

参考

1. Leetcode_easy_970. Powerful Integers;

原文地址:https://www.cnblogs.com/happyamyhope/p/11316918.html

时间: 2024-10-10 11:33:11

【Leetcode_easy】970. Powerful Integers的相关文章

【leetcode】Divide Two Integers (middle)☆

Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. 思路: 尼玛,各种通不过,开始用纯减法,超时了. 然后用递归,溢出了. 再然后终于开窍了,用循环,把被除数每次加倍去找答案,结果一遇到 -2147483648 就各种不行, 主要是这个数一求绝对值就溢出了. 再然后,受不了了,看答案. 发现,大家都用long long来解决溢

【leetcode】Divide Two Integers

题目: Divide two integers without using multiplication, division and mod operator. 解析:不使用乘号.除号和余号实现两个整数的除法.该题可以利用移位操作数求解,主要分为三个步骤: (1)先求两个int类型整数的绝对值,注意要将int类型转化成long类型才能求绝对值:因为int类型的范围是-2147483648~2147483647,如果某个数为-2147483648,其绝对值会溢出. (2)对被除数a和除数b进行移位

Leetcode 970. Powerful Integers

Brute Force(暴力) class Solution(object): def powerfulIntegers(self, x, y, bound): """ :type x: int :type y: int :type bound: int :rtype: List[int] """ ans=[] for i in range(20): for j in range(20): a=x**i+y**j if a<=bound:

【leetcode_easy】543. Diameter of Binary Tree

problem 543. Diameter of Binary Tree 参考 1. Leetcode_easy_543. Diameter of Binary Tree; 完 原文地址:https://www.cnblogs.com/happyamyhope/p/10943221.html

【leetcode_easy】551. Student Attendance Record I

problem 551. Student Attendance Record I 参考 1. Leetcode_easy_551. Student Attendance Record I; 完 原文地址:https://www.cnblogs.com/happyamyhope/p/10947954.html

【Leetcode_easy】599. Minimum Index Sum of Two Lists

problem 599. Minimum Index Sum of Two Lists 参考 1. Leetcode_easy_599. Minimum Index Sum of Two Lists; 完 原文地址:https://www.cnblogs.com/happyamyhope/p/11059712.html

【Leetcode_easy】617. Merge Two Binary Trees

problem 617. Merge Two Binary Trees 参考 1. Leetcode_easy_617. Merge Two Binary Trees; 完 原文地址:https://www.cnblogs.com/happyamyhope/p/11076297.html

【Leetcode_easy】682. Baseball Game

problem 682. Baseball Game 参考 1. Leetcode_easy_682. Baseball Game; 完 原文地址:https://www.cnblogs.com/happyamyhope/p/11091366.html

【Leetcode_easy】680. Valid Palindrome II

problem 680. Valid Palindrome II 参考 1. Leetcode_easy_680. Valid Palindrome II; 完 原文地址:https://www.cnblogs.com/happyamyhope/p/11091358.html