-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReview.txt
More file actions
396 lines (345 loc) · 10.6 KB
/
Copy pathReview.txt
File metadata and controls
396 lines (345 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
--------------------------------
---Binary Search 7, Dec 2018---
--------------------------------
def binary_search(nums, target):
if nums == None:
return -1 //
left = 0
right = len(nums) - 1
while i + 1 < j:
mid = left + (right - left) / 2
if nums[mid] < target:
left = mid + 1
continue
if nums[mid] > target:
right = mid - 1
continue
if nums[mid] == target:
return mid
continue
if nums[i] == target:
return left
else:
return right
Problem:
63: Search in Rotated Sorted Array
75: Find Peak Element
140: Fast Power
159: Find Minimum inRotated Sorted Array
428: Pow(x, n) ***
447: Search in a Big Sorted Array
458: Last Position of Target
460: Find K Closest Elements
585: Maximum Number in Mountain Sequence
----------------------------------------
Binary Search & Two Poiners 8, Dec 2018
----------------------------------------
Problem:
**:https://github.com/ZhengkaiZ/Algorithm-Record/blob/master/Try/BinarySearch.py
56: Two Sum (Sorted or Not)
160: Find Minimum in Rotated Sorted Array II (Binary Search Not Working on this case)
228: Middle of the Linked List
608: Two Sum II Input array is sorted
----------------------------------------
Two Poiners & BFS 9, Dec 2018
----------------------------------------
Two Pointer Problem:
Merge Sort, Quick Sort, Quick Search
57: 3Sum (Time to remove duplciate)
143: Sort Colors II ***
521. Remove Duplicate Numbers in Array
539: Move Zeroes **
587: Two Sum - Unique pairs
609: Two Sum - Less than or equal to target
----------------------------------------
Two Poiners & BFS 10, Dec 2018
----------------------------------------
Quick Select:
5: Kth Largest Element (Time Limit, Review)
69. Binary Tree Level Order Traversal
127: Toplogical Sorting
433: Number of Islands
615: Course Schedule
--------------------------------------------
BFS, DFS, Binary Search Tree 11, Dec 2018
--------------------------------------------
31: Partition Array
120: Word Ladder
616: Course Schedule II
611: Knight Shortest Path I
624: Remove Substring (str.find)
--------------------------------------------
EMPTY 12, Dec 2018
--------------------------------------------
--------------------------------------------
BFS, DFS, Binary Search Tree 13, Dec 2018
--------------------------------------------
137. Clone Graph
605. Sequence Reconstruction **********
618. Search Graph Nodes
900: Closest Binary Search Tree Value
596: Minimum Subtree
941: Sliding Puzzle (Optimization)
--------------------------------------------
DFS, Binary Search Tree 15, Dec 2018
--------------------------------------------
88. Lowest Common Ancestor of a Binary Tree
93: Balanced Binary Tree
246. Binary Tree Path Sum II
480: Binary Tree Paths
453: Flatten Binary Tree to Linked List ***
605. Sequence Reconstruction
902: Kth Smallest Element in a BST
--------------------------------------------
DFS, Trees 16, Dec 2018
--------------------------------------------
86: Binary Search Tree Iterator
901: Closest Binary Search Tree Value II (Two solution)
595: Binary Tree Longest Consecutive Sequence
--------------------------------------------
DFS, Trees 17, Dec 2018
--------------------------------------------
17: Subsets
18: Subsets II
136: Palindrome Partitioning
152: Combinations
153. Combination Sum II
135: Combination Sum
426. Restore IP Addresses
614: Binary Tree Longest Consecutive Sequence II
619: Binary Tree Longest Consecutive Sequence III
680: Split String
--------------------------------------------
Combination & Permutation DFS 18, Dec 2018
--------------------------------------------
108: Palindrome Partitioning II (Time Limit)
192: WildCard Matching
582: Word Break II
--------------------------------------------
Combination & Permutation DFS 19, Dec 2018
--------------------------------------------
Next Permutations:
def nextPermutation(array):
end = len(array) - 1
while end != 0 and array[end] < array[end - 1]:
end -= 1
if end != 0:
start = end - 1
right = len(array) - 1
while array[right] < array[start]:
right -= 1
tmp = array[start]
array[start] = array[right]
array[right] = tmp
left = end
right = len(array) - 1
while left <= right:
tmp = array[right]
array[right] = array[left]
array[left] = tmp
left += 1
right -= 1
return array
10. String Permutation II
15: Permutation
16: Permutations II
33: N-Queens
34: N-Queens II
52. Next Permutation
154: Regular Expression Matching
--------------------------------------------
Permutation DFS 20, Dec 2018
--------------------------------------------
197: Permutation Index
829: Word Pattern II
--------------------------------------------
DFS 20, Dec 2018
--------------------------------------------
121: Word Ladder II
132: Word Search II
198: Permutation Index II ***
634: Word Squares (Better Solution Needed)
----------------------------------------------
DFS and Advance Data Structures 21, Dec 2018
----------------------------------------------
147: Narcissistic Number (Python Time Exceed)
442. Implement Trie (Prefix Tree)
634: Word Squares (Implemented with Trie)
920. Meeting Rooms
919: Meeting Rooms II (Sweep Lines)
----------------------------------------------
DFS and Advance Data Structures 22, Dec 2018
----------------------------------------------
35: Reverse Linked List
36: Reverse Linked List II
131: The Skyline Problem (Solution Need)
156: Merge Intervals
3Sum with Mutiplicy
----------------------------------------------
DFS and Advance Data Structures 23, Dec 2018
----------------------------------------------
461: Kth Smallest Numbers in Unsorted Array (***)
143: Sort Colors II (***)
----------------------------------------------
Data Structures 26, Dec 2018
----------------------------------------------
51. Previous Permutation
52: Next Permutation(Review)
124: Longest Consecutive Sequence
173: Insertion Sort List
209: First Unique Character in a String
494: Implement Stack by Two Queues
642: Moving Average from Data Stream
657. Insert Delete GetRandom O(1)
1753: Doing HomeWork
----------------------------------------------
Data Structures & Leetcode 27, Dec 2018
----------------------------------------------
LeetCode:
681: Next Closest Time
904: Fruit Into Baskets
929: Unique Email Addresses
LintCode:
12: Min Stack
71. Binary Tree Zigzag Level Order Traversal
526. Load Balancer
544. Top k Largest Numbers
601. Flatten 2D Vector
612: K Closest Points (Two ways Quick Sort and Min Heap)
----------------------------------------------
Data Structures & Leetcode 28, Dec 2018
----------------------------------------------
LeetCode
159: Longest Substring with At Most Two Distinct Characters
399: Evaluate Division
LintCode
242. Convert Binary Tree to Linked Lists by Depth
----------------------------------------------
Data Structures & Leetcode 29, Dec 2018
----------------------------------------------
Union Find:
class UnionFind:
def __init__(self, n):
self.father = []
for i in range(n + 1):
self.father.append(i)
def find(self, target):
path = []
while self.father[target] != target:
path.append(target)
target = self.father[target]
for n in path:
self.father[n] = target
return target
def union(self, a, b):
self.father[self.find(a)] = self.find(b)
Leetcode:
683: K Empty Slots (****)
399. Evaluate Division(Union Find Optimization ***)
323: Number of Connected Components in an Undirected Graph (Union ind)
Lintcode:
----------------------------------------------
Data Structures & Leetcode 30, Dec 2018
----------------------------------------------
LeetCode:
857: Minimum Cost to Hire K Workers
LintCode:
535. House Robber III
570. Find the Missing Number II
892. Alien Dictionary
1210. Increasing Subsequences
1659: Sell or Buy Stock V
----------------------------------------------
Data Structures & Leetcode 2, Jan 2019
----------------------------------------------
124: Longest Consecutive Sequence (O(n))
----------------------------------------------
Data Structures & Leetcode 3, Jan 2019
----------------------------------------------
Union Find:
Number of Islands
Longest Consecutive Sequence
Surrounded Regions
Most Stones Removed with Same Row or Column
LeetCode:
299: Bulls and Cows
222: Count Complete Tree Nodes
LintCode
544. Top k Largest Numbers
1029. Cheapest Flights Within K Stops
----------------------------------------------
Data Structures & Leetcode 4, Jan 2019
----------------------------------------------
LeetCode:
222: Count Complete Tree Nodes
642: Design Search Autocomplete System
833: Find And Replace in String
LintCode:
545. Top k Largest Numbers II
----------------------------------------------
Data Structures & Leetcode 5, Jan 2019
----------------------------------------------
LintCode:
134: LRU Cache
138. Subarray Sum
547: Intersection of Two Arrays
839: Merge Two Sorted Interval Lists
----------------------------------------------
Data Structures & Leetcode 6, Jan 2019
----------------------------------------------
129. Rehashing
405. Submatrix Sum
486: Merge K Sorted Arrays
577. Merge K Sorted Interval Lists
944. Maximum Submatrix
Pending:
654. Sparse Matrix Multiplication
----------------------------------------------
Data Structures & Leetcode 8, Jan 2019
----------------------------------------------
LeetCode:
11. Container With Most Water
42. Trapping Rain Water
238. Product of Array Except Self
----------------------------------------------
Data Structures & Leetcode 9, Jan 2019
----------------------------------------------
LintCode:
32. Minimum Window Substring
148. Sort Colors
406. Minimum Size Subarray Sum
625. Partition Array II
LeetCode:
35: Search Insert Position
659: Split Array into Consecutive Subsequences
777: Swap Adjacent in LR String
939: Minimum Area Rectangle
Three Pointers:
pl, pr = 0, len(nums) - 1
i = 0
while i <= pr:
if nums[i] < low:
nums[pl], nums[i] = nums[i], nums[pl]
pl += 1
i += 1
elif nums[i] > high:
nums[pr], nums[i] = nums[i], nums[pr]
pr -= 1
else:
i += 1
----------------------------------------------
Data Structures & Leetcode 10, Jan 2019
----------------------------------------------
Pending:
508: Wiggle Sort
LeetCode:
5: Longest Palindromic Substring
Lintcode:
65. Median of two Sorted Arrays
----------------------------------------------
Data Structures & Leetcode 12, Jan 2019
----------------------------------------------
1. 跳楼方法 House Robber Decode Way
2. Merge Interval, Insert Interval
3. Rectangle Overlap
4. Valid Word Abbreviation