【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; ; a<bound; a*=x)// { ; a+b<=bound; b*=y) { tmp.insert(a+b);// ) break;// } ) break; } retur…
题目如下: Given two non-negative integers x and y, an integer is powerful if it is equal to x^i + y^j for some integers i >= 0 and j >= 0. Return a list of all powerful integers that have value less than or equal to bound. You may return the answer in a…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力搜索 日期 题目地址:https://leetcode.com/problems/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 integers…
题目标签: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…
Given two non-negative integers x and y, an integer is powerful if it is equal to x^i + y^j for some integers i >= 0 and j >= 0. Return a list of all powerful integers that have value less than or equal to bound. You may return the answer in any ord…
Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. 思路: 尼玛,各种通不过,开始用纯减法,超时了. 然后用递归,溢出了. 再然后终于开窍了,用循环,把被除数每次加倍去找答案,结果一遇到 -2147483648 就各种不行, 主要是这个数一求绝对值就溢出了. 再然后,受不了了,看答案. 发现,大家都用long long来解决溢…
Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. 解题思路: 模拟除法运算,但是不能试用 * / % 操作. 先思考边界条件,再开始做题: 0.除数为0无意义,需要和出题人沟通此边界是否存在(leetcode中并未考察除数为0的情况,默认除数不为0): 1.传入被除数/除数两个int做除法,什么情况返回值overflow:被…
Divide two integers without using multiplication, division and mod operator. class Solution { public: int divide(int dividend, int divisor) { ? -(long long)dividend : dividend; ? -(long long)divisor : divisor; && divisor >= ) || (dividend <=…
实现两个整数的除法,不许用乘法.除法和求模.题目被贴上了BinarySearch,但我没理解为什么会和BinarySearch有关系.我想的方法也和BS一点关系都没有. 很早以前我就猜想,整数的乘法是不是总是可以用移位和加法来实现?当然可以了,任何整数都可以写成2n或2n+1的形式,移位就是那个乘以2,加法就是最后的+1了嘛.复杂度是O(1),因为整数的移位最多32次,因此在循环中移位的次数也极其有限. 例如123/5: 5 123 <<1 <<1 <<1 <&l…
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:…
problem 1021. Remove Outermost Parentheses 参考 1. Leetcode_easy_1021. Remove Outermost Parentheses; 完…
problem 1022. Sum of Root To Leaf Binary Numbers 参考 1. Leetcode_easy_1022. Sum of Root To Leaf Binary Numbers; 完…
problem 1025. Divisor Game 参考 1. Leetcode_easy_1025. Divisor Game; 完…
problem 1029. Two City Scheduling 参考 1. Leetcode_easy_1029. Two City Scheduling; 完…
problem 1030. Matrix Cells in Distance Order 参考 1. Leetcode_easy_1030. Matrix Cells in Distance Order; 完…
problem 1033. Moving Stones Until Consecutive 参考 1. Leetcode_easy_1033. Moving Stones Until Consecutive; 完…
problem 1037. Valid Boomerang 参考 1. Leetcode_easy_1037. Valid Boomerang; 完…
problem 1042. Flower Planting With No Adjacent 参考 1. Leetcode_easy_1042. Flower Planting With No Adjacent; 完…
problem 1046. Last Stone Weight 参考 1. Leetcode_easy_1046. Last Stone Weight; 完…
problem 1047. Remove All Adjacent Duplicates In String 参考 1. Leetcode_easy_1047. Remove All Adjacent Duplicates In String; 完…
problem 1051. Height Checker solution class Solution { public: int heightChecker(vector<int>& heights) { vector<int> orders = heights; sort(orders.begin(), orders.end()); ; ; i<heights.size(); i++) { if(heights[i]!=orders[i]) res++; } r…
problem 1071. Greatest Common Divisor of Strings solution class Solution { public: string gcdOfStrings(string str1, string str2) { return (str1+str2==str2+str1) ? (str1.substr(, gcd(str1.size(), str2.size()))) : ""; } }; 参考 1. Leetcode_easy_1071…
problem 1154. Day of the Year solution class Solution { public: int dayOfYear(string date) { // 平年 闰年 ] = {, , , , , , , , , , , }; , )), m = stoi(date.substr(, )), d = stoi(date.substr()); && y % == && (y % != || y % == )) d++;//leap year…
problem 1170. Compare Strings by Frequency of the Smallest Character 参考 1. Leetcode_easy_1170. Compare Strings by Frequency of the Smallest Character; 完…
problem 1160. Find Words That Can Be Formed by Characters solution class Solution { public: int countCharacters(vector<string>& words, string chars) { ; unordered_map<char, int> charmap; for(auto ch:chars) charmap[ch]++; for(auto word:word…
problem 997. Find the Town Judge solution: class Solution { public: int findJudge(int N, vector<vector<int>>& trust) { vector<); ]]--; balance[t[]]++; } ; i<=N; i++) { ) return i; } ; } }; 参考 1. Leetcode_easy_997. Find the Town Judge…
problem 994. Rotting Oranges 参考 1. Leetcode_easy_994. Rotting Oranges; 完…
problem 993. Cousins in Binary Tree 参考 1. Leetcode_easy_993. Cousins in Binary Tree; 完…
problem 989. Add to Array-Form of Integer 参考 1. Leetcode_easy_989. Add to Array-Form of Integer; 完…
problem 985. Sum of Even Numbers After Queries class Solution { public: vector<int> sumEvenAfterQueries(vector<int>& A, vector<vector<int>>& queries) { vector<int> res; ; ==) sum +=a; for(auto query:queries) { ]]%== )…