- 博客(74)
- 收藏
- 关注
原创 leetcode刷题笔记-DP2
418.Sentence Screen Fittingclass Solution: def wordsTyping(self, sentence: List[str], rows: int, cols: int) -> int: ''' 1. Based on the above observation, in the first for loop we compute the number of words that can be pl..
2022-04-14 14:01:31
579
1
原创 leetcode刷题笔记-DFS/BFS 2
1293. Shortest Path in a Grid with Obstacles Eliminationfrom collections import dequeclass Solution: def shortestPath(self, grid: List[List[int]], k: int) -> int: ''' Solution ExplanationBecause we are trying to find the shortest
2021-02-01 15:10:14
400
1
原创 [System Design] How Redis expires keys
How Redis expires keysRedis keys are expired in two ways: a passive way, and an active way.A key is passively expired simply when some client tries to access it, and the key is found to be timed out.Of course this is not enough as there are expired keys
2021-01-25 14:30:25
187
原创 [System Design] Message Queue
Message Queue为什么使用消息队列https://aws.amazon.com/message-queue/benefits/解耦Message queues remove dependencies between components and significantly simplify the coding of decoupled applications. Software components aren’t weighed down with communications cod
2020-11-14 15:32:34
328
原创 [System Design] CAP Theorem, AP,CP
CAP 理论在分布式系统里面,CAP肯定是必须知道的,对于系统设计也会经常遇到partition的问题,某个service被隔离了,这时候就得用上CAP理论。CAP 定义PPartition tolerance: The system continues to operate despite an arbitrary number of messages being dropped (or delayed) by the network between nodesP就是在分布式环境中,由于网络的问
2020-11-06 14:32:34
200
原创 [System Design] Recommendation System - Collaborative Filtering
推荐算法Reference: youtube.com/watch?v=3ecNC-So0r4]
2020-10-28 01:05:30
251
原创 [System Design] Booking System
Ticket Booking SystemAnalysisService根据需求的功能,我们分成以下几个servicesAccountServiceSearchServiceDetailServiceBookingServicePaymentServiceNotifyServiceCancelServiceDatabaseUser DBInventory Grid DBOrder DBUser db里面可以有其他用户相关的表,比如一个User可以有多个email,多
2020-10-26 14:52:09
582
原创 [System Design] Log System
Distributed Log SystemHow to have enough information in the log for you to searchRequest - Correction idResponse - Unique idStandard log format, or have a service to transfer the logs into a standard formatRequest contextIssuesAvoid PII data (Pe
2020-10-26 07:46:17
316
原创 [System Design] Load Balancer 和 Reverse Proxy
Load Balancer前言一致性哈希和load balancer系统设计中有一定关连,系统设计中可以一起提。一致性哈希在另外一篇文章中写,本文不提。Load balancer可以把请求分配到合适的worker上去处理。 Load balancer 并不是路由到某个具体的api,所以概览上load balancer 和api gateway是不一样的。LB和reverse proxy概念上也是不一样的。Load BalancerLoad Balancer的优点Preventing requ
2020-10-25 07:58:54
480
2
原创 [System Design] Consistent Hashing
Consistent Hashing 一致性哈希算法无论是数据库scale up, 负载均衡算法等只要是分布数据、请求又能让系统知道该去哪里找,就能用到一致性哈希算法。例子:我们有一个数据库用来存储用户数据。随着时间增长,数据量太大,我们希望有更多台数据库例如5台来平均的分担存储的数据。那么,我们的系统或者load balancer怎么知道具体的某个数据是存在哪台数据库呢?我们可以通过简单的mod算法,比如说user_id % 5的结果来选择该把数据存储在哪台数据库,后面读的时候也通过%5来找到对应的
2020-10-20 13:53:48
217
原创 [System Design] High Level Workflow
System Design整个的High Level流程以及需要掌握的知识4S Analysis1. Scenario 场景需要设计哪些功能,有哪些用例,有多大的访问量等。2. Service 服务将整个系统拆分成多个小系统,各司其职。3. Storage 存储数据应该如何存储和访问。4. Scale 升级遇到瓶颈如何升级,未来可能遇到的问题和解决方案。Scenario列出所有需要设计的功能选出核心功能,因为时间太多不可能实现所有功能,优先实现核心功能讨论并发用户/请求的数量 D
2020-10-20 12:58:09
353
原创 [System Design] Master Slave Replication Architecture
Master Slave Replication系统设计中Replica是必不可少的,主从复制是常用的一种实现replica的方式。一句话概括什么是Master Slave Replication: Master数据源的数据异步的备份到Slaves数据源。无论在Mysql, Redis, MongoDB 等类型数据存储中都是存在直接可使用的主从复制,通过配置就可以直接使用,这里不提。MySQL Master-Slave Replication Architecture所有Master的数据库的
2020-10-20 11:48:22
353
原创 Leetcode刷题笔记-Array2
386.Lexicographical Numbersclass Solution(object): def lexicalOrder(self, n): def dfs(num): if num > n: return res.append(num) for i in xr...
2019-03-24 11:36:46
374
1
原创 Python多继承
参考了这篇博客打了一遍:Python - 对多继承以及super的一些了解class D(object): def foo(self): print "class D"class B(D): passclass C(D): def foo(self): print "class C"class A(B, C): pa...
2019-03-23 09:59:15
471
原创 Leetcode刷题笔记-两点间距离
675.Cut Off Trees for Golf Eventclass Solution(object): def cutOffTree(self, forest): # add border 0 so we do not need to index-checks later on forest.append([0] * len(for...
2019-03-16 06:16:12
769
原创 leetcode刷题整理-用java做的题
JAVA一些语法整理:Queue:Queue<String> queue = new LinkedList<String>();queue.offer("a"); // 添加一个元素并返回true queue.poll(); // get and pop the first elementqueue.peek(); // 返回队列头部的元素 ...
2019-03-13 04:07:47
3821
原创 leetcode刷题笔记-substring题
76.Minimum Window Substring有模板的题!https://leetcode.com/problems/minimum-window-substring/discuss/26808/Here-is-a-10-line-template-that-can-solve-most-'substring'-problemsclass Solution(object)...
2019-03-11 08:59:32
542
原创 Leetcode刷题笔记-两个字符串比较dp
72.Edit Distancef(i, j) := minimum cost (or steps) required to convert first i characters of word1 to first j characters of word2class Solution(object): def minDistance(self, word1, word...
2019-03-10 08:56:22
750
1
原创 Leetcode刷题笔记-最大矩形,最大正方形
221.Maximal Square思路:This problem can be solved by dynamic programming. They key to DP is the state equation. In this problem, we define the state asthe maximal size of the square that can be ...
2019-03-10 06:22:48
688
原创 Some Java Knowledge Review
SetHashMapReference:https://blog.youkuaiyun.com/jiary5201314/article/details/51439982HashMapis a Map based collection class that is used for storing Key & value pairs. Structure: It has an ...
2019-03-09 07:56:26
302
原创 leetcode刷题笔记-0-1knapsack背包问题
474. Ones and Zeroes DP 01背包问题思路: For dp[i][j][k], we can get it by fetching the current string i or discarding the current string, which would result in dp[i][j][k] = dp[i-1][j-numOfZero(strs[i...
2019-02-26 09:19:17
1562
2
原创 leetcode刷题笔记-graph
399.Evaluate Divisionclass Solution(object): def calcEquation(self, equations, values, queries): graph = collections.defaultdict(set) for i, vertices in enumerate(eq...
2019-02-21 07:04:55
403
1
原创 leetcode刷题笔记-two pointer
713.Subarray Product Less Than KTime is O(N) and space is O(1)class Solution(object): def numSubarrayProductLessThanK(self, nums, k): i = re = product = 0 for j, v in enumera...
2019-01-12 01:05:19
429
1
原创 leetcode刷题笔记-难题整理
472.Concatenated Words和这题类似的139.Word Breakhttps://leetcode.com/problems/word-break/description/解法一DPpython超时,但是JAVA解法可以通过。也是139题的解法延伸。class Solution(object): def findAllConcatenate...
2018-11-30 05:23:35
895
原创 leetcode刷题笔记-Greedy贪婪算法
330.Patching Arrayclass Solution(object): def minPatches(self, nums, n): i, far, re = 0, 0, 0 nums = sorted(nums) while far < n : if i < len(nums...
2018-11-22 00:39:20
1142
1
原创 NLP-Text Classifiers for Sentiment Analysis
Overview1.Text Classification:In this assignment, you will use scikit-learn, a machine learning toolkit in Python, to implement text classifiers for sentiment analysis. Please read all instruction...
2018-11-08 05:35:39
711
原创 leetcode刷题笔记-Monotonic queue/Stack
239.Sliding Window Maximumhttps://www.youtube.com/watch?v=2SXqBsTR6a8class Solution(object): def maxSlidingWindow(self, nums, k): """ :type nums: List[int] :type k...
2018-10-15 23:06:57
868
1
原创 leetcode刷题笔记-Parentheses
22.Generate Parenthesesdfs stack思路:If you have two stacks, one for n "(", the other for n ")", you generate a binary tree from these two stacks of left/right parentheses to form an output st...
2018-10-14 09:32:31
406
1
原创 leetcode笔记-union find并查集
parents = range(n) rank = [0] * n def find(edge): if parents[edge] != edge: parents[edge] = find(parents[edge]) return parents[edge] ...
2018-10-12 08:49:14
773
1
原创 leetcode刷题笔记-trie
复习时候做421642.Design Search Autocomplete Systemclass TrieNode(): def __init__(self): self.children = collections.defaultdict(TrieNode) self.isEnd = False self.rank ...
2018-10-06 08:07:22
743
原创 leetcode刷题笔记-design
588.Design In-Memory File System在trie分类362.Design Hit Counterclass HitCounter(object): # hit: O(1). get_hit: O(300). This solution will scale perfectly! def __init__(self): ...
2018-10-03 10:07:24
630
1
原创 leetcode刷题笔记-binary search
410.Split Array Largest Sum还有一种dp的解法,没有二分法好,写在dp分类里面思路:https://leetcode.com/problems/split-array-largest-sum/discuss/89817/Clear-Explanation%3A-8ms-Binary-Search-Java用Go写的:func split...
2018-09-24 23:40:32
592
1
原创 Machine Learning Project1, KNN
HeaderName: Shusen Wu OS: Win10 Cpu: I7-7700 Language: Python3.6 Environment: Jupyter Notebook library: numpymatplotlib.pyplotcollections timeoperator ReferenceMachine Learning in A...
2018-09-15 09:07:50
712
原创 Leetcode刷题笔记-不知道怎么分类的题
731.My Calendar IIoverlap的部分放重复的,只要检查overlap。class MyCalendarTwo(object): # O(N) def __init__(self): self.overlap = [] self.nums = [] def book(self, start, end):...
2018-09-12 23:43:35
439
原创 Leetcode刷题笔记-sort
Quick Sort O(nlogn)选最后一个num为pivot,从left遍历到right, 比它小的元素全部放到前面去。然后再把自己也放到前面去,它后面的都比它大,它前面的都比它小。返回它的索引。然后重复 它的左边,和右边按照之前的步骤。def quickSort(arr, l, r): if l < r: idx = partition(arr,......
2018-09-11 10:05:22
521
1
原创 Leetcode刷题笔记-linkedlist
369.Plus One Linked Listp1指向最后面非9的数字。p2指向结尾。 class Solution(object): def plusOne(self, head): # two pointers dummy = ListNode(0) dummy.next = head p1 = p2 = ...
2018-09-08 05:41:59
788
1
原创 leetcode刷题笔记-bit & bitmask
338.Counting Bitsclass Solution(object): def countBits(self, num): dp = [0] * (num+1) for i in xrange(num+1): dp[i] = dp[i/2] + i%2 return dp260.Sin...
2018-09-07 11:49:48
391
1
原创 leetcode刷题笔记-merge sort
Merge sort我研一上学期时候的笔记:148.Sort List简直就是我的笔记的代码版本。# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = No...
2018-09-07 10:31:49
908
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人