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 Station { | |
| Station(int capacity = 0, int car = 0): capacity(capacity), car(car) {} | |
| int capacity; | |
| int car; | |
| }; | |
| bool pick(list<Station>& workers, list<int>& q) { | |
| if (q.empty()) return false; | |
| int car = q.front(); | |
| for (auto& station: workers) { |
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
| int toNum(vector<int>& digits) { | |
| int result = 0; | |
| for (int num: digits) { | |
| result *= 10; | |
| result += num; | |
| } | |
| return result; | |
| } | |
| vector<int> toVec(int num) { |
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: | |
| struct TreeNode { | |
| TreeNode(int val) : val(val) {} | |
| int val = 0; | |
| int depth = 0; | |
| int lCount = 0; | |
| int rCount = 0; | |
| TreeNode* left = nullptr; | |
| TreeNode* right = nullptr; |
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 binary tree node. | |
| * struct TreeNode { | |
| * int val; | |
| * TreeNode *left; | |
| * TreeNode *right; | |
| * TreeNode() : val(0), left(nullptr), right(nullptr) {} | |
| * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} | |
| * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} | |
| * }; |
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 Node { | |
| Node* left = nullptr; | |
| Node* right = nullptr; | |
| int val = 0; | |
| int height = 0; | |
| } | |
| int getHeight(Node *root) { | |
| if (!root) return -1; | |
| return height; |
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 MinMaxQueue { | |
| public: | |
| void push(int v) { | |
| if (back.empty()) { | |
| back.emplace(v, v, v); | |
| } else { | |
| back.emplace(v, std::min(v, back.top().min), std::max(v, back.top().max)); | |
| } | |
| } | |
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 DoubleLinkedList { | |
| struct Node { | |
| Node(){}; | |
| Node(int key, int value) : key(key), value(value) {}; | |
| Node* next = nullptr; | |
| Node* prev = nullptr; | |
| int key = -1; | |
| int value = -1; | |
| int rank = 1; | |
| }; |
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
| #include <iostream> | |
| #include <memory> | |
| #include <vector> | |
| #include <string> | |
| using namespace std; | |
| struct Trie { | |
| array<unique_ptr<Trie>, 26> nodes; | |
| bool isEnd = false; |
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 lengthOfLIS(vector<int>& nums) { | |
| int result = 0; | |
| int N = nums.size(); | |
| vector<int> dp(N, 1); | |
| for (int i = 0; i < N; ++i) { | |
| for (int j = i - 1; j >= 0; --j) { | |
| if (nums[j] < nums[i]) { | |
| dp[i] = max(dp[i], dp[j] + 1); |
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 lowerBound(const vector<int>& nums, int value) { | |
| int l = 0; | |
| int r = nums.size(); | |
| while (l < r) { | |
| int mid = (l+r) / 2; | |
| if (nums[mid] < value) { | |
| l = mid + 1; | |
| } else { |
NewerOlder