https://www.gravatar.com/avatar/ab4373c6bd8c97aaf40c1042a5aad224?s=240&d=mp

403. Frog Jump

https://leetcode.com/problems/frog-jump/ https://leetcode.com/problems/frog-jump/submissions/1032720945/ class Solution { public: bool check(unordered_map<int, bool>& exist, unordered_map<int, unordered_map<int, bool>> &inq, int lastStone, int nextStone, int jumpUnits) { if(inq[nextStone][jumpUnits]) return false; if(nextStone > lastStone) return false; if(!exist[nextStone]) return false; return true; } bool canCross(vector<int>& stones) { if(stones == (vector<int>){0,1}) { return true; } int n = stones.size(); if(stones.back() > (n * (1 + n - 1) / 2)) { return false; } unordered_map<int, bool> exist; for(int i : stones) exist[i] = true; priority_queue<pair<int, int>, vector<pair<int, int>>, less<pair<int, int>>> q; unordered_map<int, unordered_map<int, bool>> inq; if(stones[1] !

68. Text Justification

https://leetcode.com/problems/text-justification/ https://leetcode.com/problems/text-justification/submissions/1030637814/ class Solution { public: vector<string> fullJustify(vector<string>& words, int maxWidth) { vector<string> ans; for(int i = 0; i < words.size(); ){ string tans = ""; int j = i; while(j != words.size() && tans.size() + words[j].size() <= maxWidth) { tans += words[j]; if(tans.size() != maxWidth) tans += " "; j++; } if(j == words.size()) { ans.push_back(tans + string(maxWidth - tans.size(), ' ')); } else { ans.push_back(rerrange(tans, maxWidth)); } i = j; } return ans; } inline string rerrange(string s, int maxWidth) { int space = 0; vector<string> split; string ts = ""; for(auto c : s) { if(c == ' ') space++, split.

239. Sliding Window Maximum

https://leetcode.com/problems/sliding-window-maximum/ https://leetcode.com/problems/sliding-window-maximum/submissions/1022554836/ class Solution { public: vector<int> maxSlidingWindow(vector<int>& nums, int k) { priority_queue<pair<int, int>, vector<pair<int,int>>, less<pair<int,int>>> q; for(int i = 0; i < k; ++i) { q.push(pair(nums[i],i)); } vector<int> ans; ans.push_back(q.top().first); for(int i = k; i < nums.size(); ++i) { q.push(pair(nums[i], i)); auto t = q.top(); while(t.second <= i - k) { q.pop(); t = q.top(); } ans.push_back(q.top().first); } return ans; } };

LeetCode Biweekly Contest 91 Tutorial

Q2 Tutorial An easy dp problem, for dp[i], means how many good string of length i. Init dp[zero] = 1, dp[one] = 1 (if one == zero, then dp[one] = 2); So dp[i] = dp[i - zero] + dp[i - one]. After calculate all dp, sum up dp[low] to dp[high]. Accepted Code class Solution { public: long long dp[100005]; int countGoodStrings(int low, int high, int zero, int one) { memset(dp, 0, sizeof(dp)); dp[zero]++; dp[one]++; for(int i = min(zero, one); i <= high; ++i){ if(i > zero) dp[i] += dp[i - zero]; if(i > one) dp[i] += dp[i - one]; dp[i] %= 1000000007; } long long ans = 0; for(int i = low; i <= high; ++i){ ans += dp[i]; ans %= 1000000007; } return ans; } }; Q3 Tutorial First, from root 0, bfs all tree to find where bob is.

2022.10 Daily LeetCode Coding Problems Tutorial

If you get any problem of my code or you find something wrong, just leave a comment or contact with me, I’ll response you as fast as I can if I see it. If this tutorial helps you well, you can subscribe my website, every time I update any Tutorial, I’ll send an email to all subscribers. 10-31 766. Toeplitz Matrix Difficulty: Easy Accepted Code class Solution { public: bool isToeplitzMatrix(vector<vector<int>>& matrix) { vector<int> n[int(matrix.

Codeforces 1697 D Tutorial

D. Guess The String Problem summary The Jury chosen a stringS consisting of n characters; each character of S is a lowercase Latin letter. You may ask query in two types: 1 i - query for the letterSi 2 l r - query the size of character set of Sl,Sl+1,......,Sr You are allowed to ask no more than 26 queries of the first type, and no more than 6000 queries of the second type.