题目如下: 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…
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 <=…
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 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 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) { ]]%== )…