随笔分类 -  leetcode

摘要:把top 100重新刷一遍 class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { unordered_map<int,int> um; for(int i=0;i<nums.size();++i) { 阅读全文
posted @ 2020-07-03 22:00 qiujiejie 阅读(91) 评论(0) 推荐(0)
摘要:https://www.cnblogs.com/grandyang/p/5144918.html 1. class Solution { public: int nthSuperUglyNumber(int n, vector<int>& primes) { vector<int> res(1,1) 阅读全文
posted @ 2020-06-30 10:18 qiujiejie 阅读(138) 评论(0) 推荐(0)
摘要:1. class Solution { public: int missingNumber(vector<int>& nums) { sort(nums.begin(),nums.end()); for(int i=0;i<nums.size();++i) { if(nums[i]!=i) retu 阅读全文
posted @ 2020-06-29 10:35 qiujiejie 阅读(145) 评论(0) 推荐(0)
摘要:https://www.cnblogs.com/grandyang/p/4741934.html class Solution { public: bool isUgly(int num) { if(num<=0) return false; while(num%2==0) num/=2; whil 阅读全文
posted @ 2020-06-28 09:47 qiujiejie 阅读(115) 评论(0) 推荐(0)
摘要:class Solution { public: int addDigits(int num) { while(num>=10) { int sum=0; while(num) { sum+=num%10; num/=10; } num=sum; } return num; } }; 阅读全文
posted @ 2020-06-28 09:41 qiujiejie 阅读(139) 评论(0) 推荐(0)
摘要:1. class Solution { public: bool isPowerOfTwo(int n) { if(n<=0) return false; while(n!=1) { if(n%2) return false; n/=2; } return true; } }; 2. 如果是2的倍数 阅读全文
posted @ 2020-06-27 18:13 qiujiejie 阅读(102) 评论(0) 推荐(0)
摘要:https://www.cnblogs.com/grandyang/p/4570699.html class Solution { public: int calculate(string s) { int sign=1,res=0,n=s.size(); stack<int> sta; for(i 阅读全文
posted @ 2020-06-27 17:54 qiujiejie 阅读(84) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/rectangle-area/discuss/705462/C-36-ms-100-O(1)-15.4-mb-100-O(1) class Solution { public: int computeArea(int A, int B, i 阅读全文
posted @ 2020-06-26 08:44 qiujiejie 阅读(81) 评论(0) 推荐(0)
摘要:1. class Solution { public: string frequencySort(string s) { map<char,int> m; for(auto& c:s) { ++m[c]; } string str;char c; while((c=get_max(m))) { if 阅读全文
posted @ 2020-06-24 23:42 qiujiejie 阅读(108) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/ugly-number-ii/discuss/591634/C%2B%2B-easy-O(n)-DP 一个丑数乘以2/3/5仍然是一个丑数;t2、t3、t5记录当前应该乘以2、3、5的数字的位置,选择乘积最小的一个。 class Solut 阅读全文
posted @ 2020-05-08 09:59 qiujiejie 阅读(110) 评论(0) 推荐(0)
摘要:https://www.cnblogs.com/grandyang/p/4518674.html 第一个和最后一个数字不可以同时选择,所以分为两种情况计算,分别是[0...m-1]和[1....m],取最大值。 计算每个位置的最大值时,该位置i的最大值只和i-1、i-2的值有关。 class Sol 阅读全文
posted @ 2020-05-07 10:37 qiujiejie 阅读(115) 评论(0) 推荐(0)
摘要:https://www.cnblogs.com/grandyang/p/4295761.html class Solution { public: int maxProfit(int k, vector<int>& prices) { if(prices.empty()) return 0; if( 阅读全文
posted @ 2020-05-07 09:05 qiujiejie 阅读(133) 评论(0) 推荐(0)
摘要:https://www.cnblogs.com/grandyang/p/4233035.html dp[i][j]表示当前位置的最小起始血量;从右下往左上推。 class Solution { public: int calculateMinimumHP(vector<vector<int>>& d 阅读全文
posted @ 2020-05-06 10:02 qiujiejie 阅读(109) 评论(0) 推荐(0)
摘要:leetcode 139 word break class Solution { public: bool wordBreak(string s, vector<string>& wordDict) { unordered_set<string> wordset(wordDict.begin(),w 阅读全文
posted @ 2020-05-05 10:05 qiujiejie 阅读(141) 评论(0) 推荐(0)
摘要:https://www.cnblogs.com/grandyang/p/4271456.html leetcode 132 https://www.cnblogs.com/grandyang/p/7404777.html leetcode 647 将字符串切割为回文的最小切割数:动态规划 p[i][ 阅读全文
posted @ 2020-05-04 18:12 qiujiejie 阅读(131) 评论(0) 推荐(0)
摘要:https://www.cnblogs.com/grandyang/p/4294105.html 不同的子序列: 动态规划,dp[i][j]代表s[0...i]中t[0...j]有的个数。写出矩阵,找规律。 class Solution { public: int numDistinct(strin 阅读全文
posted @ 2020-05-04 17:09 qiujiejie 阅读(109) 评论(0) 推荐(0)
摘要:https://www.cnblogs.com/grandyang/p/4298664.html 动态规划,dp[i][j]为true表示s1[i-1]可以与s3[i+j-1]匹配或s2[j-1]可以与s3[i+j-1]匹配 class Solution { public: bool isInter 阅读全文
posted @ 2020-04-28 14:26 qiujiejie 阅读(149) 评论(0) 推荐(0)
摘要:https://www.cnblogs.com/grandyang/p/4301096.html https://www.cnblogs.com/grandyang/p/4299608.html 卡塔兰数:https://zh.wikipedia.org/wiki/%E5%8D%A1%E5%A1%9 阅读全文
posted @ 2020-04-23 10:36 qiujiejie 阅读(167) 评论(0) 推荐(0)
摘要:https://www.cnblogs.com/grandyang/p/4313384.html 动态规划,如果当前数字不为0,则当前数字可以单独转换,有dp[i-1]种方法(dp[i-1]的每一种方法都加上当前的转换);如果和前面一个数字组成的数字大于0,小于27,s[i-2]和s[i-1]可以转 阅读全文
posted @ 2020-04-23 09:27 qiujiejie 阅读(103) 评论(0) 推荐(0)
摘要:https://www.cnblogs.com/grandyang/p/4318500.html 1. 递归,每次比较字符串的i个字串是否匹配。 class Solution { public: bool isScramble(string s1, string s2) { if(s1.size() 阅读全文
posted @ 2020-04-22 10:43 qiujiejie 阅读(116) 评论(0) 推荐(0)