This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public: | |
| int searchInsert(vector<int>& nums, int target) { | |
| int len = nums.size(), lo = 0, hi = len; | |
| while (lo < hi) { | |
| int mid = lo + (hi - lo) / 2; | |
| if (nums[mid] < target) | |
| lo = mid + 1; | |
| else | |
| hi = mid; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct State | |
| { | |
| int vertex, cost; | |
| State(int v, int c) | |
| { | |
| vertex = v; | |
| cost = c; | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution | |
| { | |
| public: | |
| vector<string> split(const string& message, int limit) | |
| { | |
| int len = message.size(), k = len % limit ? len / limit + 1 : len / limit, digitsOfN = to_string(k).size(); | |
| vector<string> res; | |
| while (!canSplit(message, limit, digitsOfN, res))++digitsOfN; | |
| return res; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public: | |
| vector<vector<int>> subsets(vector<int>& nums) { | |
| vector<vector<int>> res; | |
| vector<int> curr; | |
| dfs(nums, 0, curr, res); | |
| return res; | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public: | |
| vector<vector<int>> subsetsWithDup(vector<int>& nums) { | |
| vector<vector<int>> res; | |
| vector<int> curr; | |
| sort(nums.begin(), nums.end()); | |
| dfs(nums, 0, curr, res); | |
| return res; | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public: | |
| bool backspaceCompare(string S, string T) { | |
| int len1 = S.size(), len2 = T.size(), i = len1 - 1, j = len2 - 1, cnt1 = 0, cnt2 = 0; | |
| while(i >= 0 || j >= 0) | |
| { | |
| if(S[i] == '#'){--i;++cnt1;continue;} | |
| if(T[j] == '#'){--j;++cnt2;continue;} | |
| if(cnt1){--i;--cnt1;continue;} | |
| if(cnt2){--j;--cnt2;continue;} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public: | |
| vector<int> maxSlidingWindow(vector<int>& nums, int k) { | |
| int len = nums.size(); | |
| deque<int> dq; | |
| vector<int> res; | |
| for(int i = 0; i < len; ++i) | |
| { | |
| while(dq.size() && nums[dq.back()] <= nums[i]) | |
| dq.pop_back(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| // Definition for a QuadTree node. | |
| class Node { | |
| public: | |
| bool val; | |
| bool isLeaf; | |
| Node* topLeft; | |
| Node* topRight; | |
| Node* bottomLeft; | |
| Node* bottomRight; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public: | |
| vector<double> medianSlidingWindow(vector<int>& nums, int k) { | |
| int len = nums.size(); | |
| multiset<int> smaller, larger; | |
| vector<double> res; | |
| for (int i = 0; i < len; ++i) | |
| { | |
| //erase | |
| if (i >= k) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public: | |
| vector<double> medianSlidingWindow(vector<int>& nums, int k) { | |
| int len = nums.size(); | |
| multiset<int> set(nums.begin(), nums.begin() + k); | |
| auto mid = next(set.begin(), k / 2); | |
| vector<double> res; | |
| for (int i = k; i <= len; ++i) | |
| { | |
| res.push_back((static_cast<double>(*mid) + static_cast<double>(*prev(mid, 1 - k % 2))) / 2.0); |
NewerOlder