File tree Expand file tree Collapse file tree 9 files changed +89
-31
lines changed
Expand file tree Collapse file tree 9 files changed +89
-31
lines changed Original file line number Diff line number Diff line change 11# Collection cheatsheet
22
3- ### 1) collection.Counter
3+ ## 0) Concept
4+
5+ ### 0-1) Framework
6+
7+ ### 0-2) Pattern
8+
9+ ## 1) General form
10+
11+ ### 1-1) collection.Counter
412``` python
513import collections
614s = [' a' ,' b' ,' c' ,' c' ]
@@ -10,7 +18,7 @@ print (c.keys())
1018print (c.values())
1119```
1220
13- ### 1-1 ) Important method - most_common()
21+ ### 1-2 ) Important method - most_common()
1422``` python
1523# 451 Sort Characters By Frequency
1624import collections
@@ -23,7 +31,7 @@ for item, freq in count:
2331# b 1
2432```
2533
26- ### 2 ) collection.defaultdict (int, list...)
34+ ### 1-3 ) collection.defaultdict (int, list...)
2735``` python
2836import collections
2937s = [' a' ,' b' ,' c' ,' c' ]
Original file line number Diff line number Diff line change 11# BFS cheatsheet
22
3- ### 1) General form
3+ ## 0) Concept
4+
5+ ### 0-1) Framework
6+
7+ ### 0-2) Pattern
8+
9+ ## 1) General form
410``` python
511# V1 : via collections.deque
612import collections
@@ -34,6 +40,10 @@ def bfs(root):
3440
3541```
3642
43+ ### 1-1) Basic OP
44+
45+ ## 2) LC Example
46+
3747### 2-1) Word Ladder
3848``` python
3949# 127 Word Ladder
@@ -55,4 +65,4 @@ class Solution(object):
5565 bfs.append((newWord, length + 1 ))
5666 return 0
5767
58- ```
68+ ```
Original file line number Diff line number Diff line change 11# Binary Search Cheatsheet
22
3- ### 1) General form
3+ ## 0) Concept
4+
5+ ### 0-1) Framework
6+
7+ ### 0-2) Pattern
8+
9+ ## 1) General form
410``` python
511def binary_search (nums , target ):
612 l, r = 0 , len (nums)- 1
@@ -15,6 +21,8 @@ def binary_search(nums, target):
1521 return - 1
1622
1723```
24+ ## 2) LC Example
25+
1826
1927### 2-1) For loop + binary search
2028``` python
Original file line number Diff line number Diff line change 11# Hash Map Cheatsheet
22
3- ### 1) General form
3+ ## 0) Concept
44
5+ ### 0-1) Framework
6+
7+ ### 0-2) Pattern
8+
9+ ## 1) General form
510<p align =" center " ><img src =" https://github.com/yennanliu/CS_basics/blob/master/doc/pic/hash_table_2.png " ></p >
611
712- Definition
2025
2126- Ref
2227 - https://blog.techbridge.cc/2017/01/21/simple-hash-table-intro/
23- - https://www.freecodecamp.org/news/hash-tables/
28+ - https://www.freecodecamp.org/news/hash-tables/
29+
30+ ## 2) LC Example
Original file line number Diff line number Diff line change 11# Heap cheatsheet
22
3- ### 1) General form
4- - dev
3+ ## 0) Concept
54
6- ### 2) Heap VS Stack VS Queue
7- - dev
5+ ### 0-1) Framework
86
9- ### 3) Basic OP
10- - dev
7+ ### 0-2) Pattern
118
12- ### 4-1) Heap sort
9+ ## 1) General form
10+
11+ ### 1-1) Basic OP
12+
13+ ### 1-2) Heap VS Stack VS Queue
14+
15+ ### 1-3) Heap sort
1316``` python
1417# https://docs.python.org/zh-tw/3/library/heapq.html
1518def heapsort (iterable ):
@@ -24,10 +27,11 @@ def heapsort(iterable):
2427
2528```
2629
27- ### 4-2) Priority Queue
28- - dev
30+ ### 1-4) Priority Queue
31+
32+ ## 2) LC Example
2933
30- ### 4-3 ) Kth Largest Element in a Stream
34+ ### 2-1 ) Kth Largest Element in a Stream
3135``` python
3236# 703 Kth Largest Element in a Stream
3337class KthLargest (object ):
Original file line number Diff line number Diff line change 11# Palindrome cheatsheet
22
3- ### 1) General form
3+ ## 0) Concept
4+
5+ ### 0-1) Framework
6+
7+ ### 0-2) Pattern
8+
9+ ## 1) General form
410``` python
511def check_palindrome (x ):
612 return x == x[::- 1 ]
713```
814
9- ### 2) Example
15+ ### 1-1) Basic OP
16+
17+ ## 2) LC Example
1018
11- #### 2-1)
19+ #### 2-1) Palindrome Partitioning
1220``` python
1321# 131 Palindrome Partitioning
1422class Solution (object ):
Original file line number Diff line number Diff line change 11# Queue cheatsheet
22
3- ### 1) General form
3+ ## 0) Concept
44
5- ### 2 -1) Queue
5+ ### 0 -1) Framework
66
7- ### 2-2) Double-ended Queue
7+ ### 0-2) Pattern
8+
9+ ## 1) General form
10+
11+ ### 1-1) Basic OP
12+
13+ ### 1-2) Queue
14+
15+ ### 1-3) Double-ended Queue
816``` python
917# https://pymotw.com/2/collections/deque.html
1018import collections
@@ -19,5 +27,4 @@ print ('pop_left:' , d.popleft())
1927print (d)
2028
2129```
22-
23- ### 2-3) Stack simulate Queue
30+ ### 1-4) Stack simulate Queue
Original file line number Diff line number Diff line change 11# String cheatsheet
22
3- ### 1) General form
4- - dev
3+ ## 0) Concept
54
6- ### 2) Example
5+ ### 0-1) Framework
76
8- #### 2-1) go through 2 string, keep comparing digits in eash string
7+ ### 0-2) Pattern
8+
9+ ## 1) General form
10+
11+ ## 2) LC Example
12+
13+ ### 2-1) go through 2 string, keep comparing digits in eash string
914``` python
1015# 165 Compare Version Number
1116class Solution (object ):
@@ -27,7 +32,7 @@ class Solution(object):
2732 return 0
2833```
2934
30- #### 2-2) String -> Int
35+ ### 2-2) String -> Int
3136``` python
3237# 445 Add Two Numbers II
3338# 394 Decode String
Original file line number Diff line number Diff line change 3838 - 606 Construct String from Binary Tree
3939 - 459 Repeated Substring Pattern
4040- Review:
41+ - `cheatsheet/dfs.md`
4142 - 098 Validate Binary Search Tree
4243 - [AMZ V1](https://github.com/yennanliu/CS_basics/blob/master/doc/leetcode_company_V1/Amazon%20-%20LeetCode.pdf) - 12/13
4344 - Review `data/to_review.txt`
You can’t perform that action at this time.
0 commit comments