- 博客(284)
- 收藏
- 关注
原创 CHAPTER 11: DESIGN A NEWS FEED SYSTEM
Or both?order.Params:Params:Pros:Cons:Pros:Cons:
2023-09-25 11:16:20
183
原创 CHAPTER 7: DESIGN A UNIQUE ID GENERATOR IN DISTRIBUTED SYSTEMS
Cons:Pros:Cons:available.
2023-09-19 09:14:11
127
原创 CHAPTER 4: DESIGN A RATE LIMITER
processes.Pros:Cons:seconds.Pros:Cons:Pros:Cons:Pros:Cons:ProsCons。
2023-09-14 10:43:42
154
原创 CHAPTER 3: A FRAMEWORK FOR SYSTEM DESIGN INTERVIEWS
An effective system design interview gives strong signals about aperson’s ability to collaborate, to work under pressure, and to resolve ambiguity constructively. The ability to ask good questions is also an essential skill, and many interviewers specific
2023-09-13 11:47:42
117
原创 CHAPTER 1: SCALE FROM ZERO TO MILLIONS OF USERS
simplehas limitnodes;server.Decouplingtier, etc.
2023-09-06 11:10:16
103
原创 workday vo Minimum Window Substring
哈希表+遍历子串 On2超时class Solution {public: string minWindow(string s, string t) { unordered_map<char, int> map; for(char c : t){ map[c] ++; } string ans = ""; for(int i = 0; i < s.length(); i++)
2021-12-02 12:51:45
3384
原创 leetcode 937(未完)
class Solution {public: static bool cmp(string a, string b){ int key1 = getkey(a); int key2 = getkey(b); if(a.substr(key1) == b.substr(key2)){ //cout<<a.substr(0,key1) <<' '<< a.substr(0,key2);
2021-11-16 13:29:50
4420
原创 200. Number of Islands(未完)
DFSclass Solution {public: vector<int> dir{-1,0,1,0,-1}; int numIslands(vector<vector<char>>& grid) { vector<vector<int>> visited(grid.size(), vector<int>(grid[0].size(), 0)); int res = 0;
2021-11-09 00:39:26
227
原创 245. Shortest Word Distance III
自己写的,变体双指针,极度麻烦但过了,时间复杂度On 空间复杂度Onclass Solution {public: int Min(int a, int b){ return a < b ? a : b; } int shortestWordDistance(vector<string>& wordsDict, string word1, string word2) { int flag = 0; if(w
2021-11-05 11:26:43
122
原创 207. Course Schedule(未完)
class Solution {public: bool canFinish(int numCourses, vector<vector<int>>& prerequisites) { vector<vector<int>> adj(numCourses, vector<int>(numCourses,0)); for(int i = 0; i < prerequisites.size();
2021-10-27 23:25:36
123
原创 310. Minimum Height Trees(未完)
自己做的,超时class Solution {public: vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) { vector<int> res; unordered_map<int,vector<int>> map; for(int i = 0; i < edges.size()
2021-10-26 09:57:38
107
原创 154. Find Minimum in Rotated Sorted Array II
自己做的,双指针,但是复杂度不太乐观class Solution {public: int findMin(vector<int>& nums) { int i = 0; int j = nums.size() - 1; while(i + 1 < nums.size() && j - 1 >= 0 && i <= j){ if(nums[i+1] <
2021-10-23 11:18:04
97
原创 每日一题 151. Reverse Words in a String
自己写的class Solution {public: string reverseWords(string s) { vector<string> words; int i = 0; while(s[i] == ' ' && i < s.length()){ i++; } while(i < s.length()){ strin
2021-10-20 11:17:55
100
原创 tiktokOA 1347 Minimum Number of Steps to Make Two Strings Anagram
直接过了,但很慢class Solution {public: int minSteps(string s, string t) { unordered_map<char,int> map; for(int i = 0; i < t.length(); i++){ map[t[i]]++; } for(int i = 0; i < s.length(); i++){
2021-10-04 04:21:07
166
原创 tiktokOA 1048. Longest String Chain
自己写的,超时class Solution {public: int longestStrChain(vector<string>& words) { int maxn = 1; for(int i = 0; i < words.size(); i++){ maxn = max(maxn, dfs(words[i],words)); } return maxn; }
2021-10-03 13:20:30
141
原创 tiktokOA Add Two Numbers
自己做的/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(
2021-10-03 07:31:59
114
原创 tiktokOA fizz buzz
自己做的class Solution {public: vector<string> fizzBuzz(int n) { vector<string> res; for(int i = 1; i <= n; i++){ if(i % 3 == 0){ if(i % 5 == 0){ res.push_back("FizzBuzz");
2021-10-03 06:25:58
512
原创 504 HW4
Zhen GaoS01401440Extensible[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pWggSOJV-1633068895352)(./uml.jpg)]Use Factory Design Pattern to create Balls and Strategies.Class MovingBall inherited Ball, adding strategy and name properties and fuctions that suppo
2021-10-01 15:11:59
442
原创 tiktokOA 1249. Minimum Remove to Make Valid Parentheses
过了但很慢class Solution {public: string minRemoveToMakeValid(string s) { string res = ""; stack<int> left; int n = s.length(); for(int i = 0; i < n; i++){ if(s[i] == '('){ left.push(i);
2021-09-26 11:31:15
134
原创 tiktokOA 66. Plus One
答案和我写的差不多,不看了。class Solution {public: vector<int> plusOne(vector<int>& digits) { int n = digits.size(); int i = n-1; while(i >= 0){ if(digits[i] == 9){ if(i == 0){
2021-09-25 11:06:48
143
原创 1181 · Diameter of Binary Tree
求二叉树任意两节点之间距离的最大值自己写的,这时间复杂度不得上天了,结果竟然击败了81%/** * Definition of TreeNode: * class TreeNode { * public: * int val; * TreeNode *left, *right; * TreeNode(int val) { * this->val = val; * this->left = this->right =
2021-09-14 09:06:19
92
原创 复杂数据结构 复合数据结构 146. LRU Cache (Medium)
自己写的,不知道咋错了class LRUCache {public: unordered_map<int,int> cache; unordered_map<int,int> appear; int size; int count; int time; LRUCache(int capacity) { size = capacity; count = 0; time = 0;
2021-09-06 04:36:32
257
原创 复杂数据结构 并查集 684. Redundant Connection (Medium)
class Solution {public: int Find(vector<int> &parent, int index){ if(parent[index] != index){ parent[index] = Find(parent, parent[index]); } return parent[index]; } void Union(vector<int> &am
2021-09-06 03:41:01
282
原创 图 拓扑排序 210. Course Schedule II (Medium)
class Solution {public: vector<vector<int>> edges; vector<int> visited;//0未访问 1访问中 2访问完 vector<int> stack; bool valid = true; void dfs(int i){ visited[i] = 1; for(int j : edges[i]){
2021-09-05 08:56:26
122
原创 图 二分图 785. Is Graph Bipartite? (Medium)
class Solution {public: bool isBipartite(vector<vector<int>>& graph) { int n = graph.size(); unordered_map<int,int> map; queue<int> q; for(int i = 0; i < graph.size(); i++){ if
2021-09-05 05:25:45
179
原创 树 字典树 208. Implement Trie (Prefix Tree)
自己写的, 不知道咋错了class TreeN {public: char val; vector<TreeN*> child; TreeN() { } TreeN(char val){ this->val = val; }};class Trie {public: TreeN* root; /** Initialize your data structure here. */
2021-09-05 04:30:32
196
原创 树 二叉查找树 669. Trim a Binary Search Tree
/** * 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) {} *
2021-09-05 03:46:03
145
原创 树 二叉查找树 99. Recover Binary Search Tree (Hard)
答案方法一有误,暂未知/** * 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(nul
2021-09-03 10:18:55
93
原创 树 前中后序遍历 144. Binary Tree Preorder Traversal (Medium)
不用递归,借助栈实现先序遍历/** * 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(
2021-08-31 02:16:24
163
原创 树 前中后序遍历 105. Construct Binary Tree from Preorder and Inorder Traversal (Medium)
/** * 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) {} *
2021-08-31 01:58:36
124
原创 树 层次遍历 637. Average of Levels in Binary Tree (Easy)
/** * 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) {} *
2021-08-31 01:36:35
124
原创 树 树的递归 1110. Delete Nodes And Return Forest (Medium)
自底向上删的,不用担心先入vector的节点之后又被删除。当它被删除后,上一层的函数会先判断left和right存不存在,再入vector。/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {
2021-08-31 01:22:58
145
原创 树 树的递归 101. Symmetric Tree (Easy)
一遍过,我太强了/** * 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(nullpt
2021-08-31 00:09:57
96
原创 树 树的递归 437. Path Sum III (Easy)
/** * 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) {} *
2021-08-30 03:35:35
153
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人