Git Product home page Git Product logo

leetcode-1's Introduction

Leetcode

Some nonsense

Well, It's May 2018, I graduated last week, but I'm still seeking a job. I'm jobless right now .....

I hope I can record this journey.
Trust The Process

Top interview problem

Question Done Date Code Note
1. Two Sum 2018/5/28 Here Two ways: 1. sorting + two pointers; 2. HashMap
2. Add Two Numbers 2018/6/1 Here two pointers, advacend bit
3. Longest Substring Without Repeating Characters 2018/6/4 Here Two pointers + Boolean array recording character appearing in s[slow:fast]
5. Longest Palindromic Substring 2018/6/6 Here Two pointers
8. String to Integer (atoi) 2018/6/6 Here Edge cases: 1. leading blanks; 2. '+' or '-'; 3. Integer overflow
10. Regular Expression Matching 2018/6/7 Here DP
11. Container With Most Water 2018/5/21 Here Two Pointer
13. Roman to Integer 2018/6/4 Here Math logic
14. Longest Common Prefix 2018/6/5 Here Pointer to specify index we're at + vertical iteration and comparation
15. 3Sum 2018/5/28 Here Classical Sorting + two pointers
17. Letter Combinations of a Phone Number 2018/6/6 Here Backtracking
19. Remove Nth Node From End of List 2018/6/1 Here two pointers
20. Valid Parentheses 2018/6/6 Here Stack
21. Merge Two Sorted Lists 2018/5/22 Here Two Pointer, Merge sort
22. Generate Parentheses 2018/6/6 Here Backtracking
23. Merge k Sorted Lists 2018/6/2 Here Priority Queue
26. Remove Duplicates from Sorted Array 2018/5/25 Here Two pointers
28. Implement strStr() 2018/6/5 Here Using java built-in substring() and equals()
33. Search in Rotated Sorted Array 2018/5/22 Here Binary Search
34. Search for a Range 2018/5/26 Here Binary search
38. Count and Say 2018/6/6 Here Operation of StringBuilder
41. First Missing Positive 2018/5/21 Here Using Index space
44. Wildcard Matching 2018/6/7 Here DP
48. Rotate Image 2018/5/27 Here Four pointer to denote four points on which we need to operate
49. Group Anagrams 2018/6/5 Here HashMap; Firstly sort the string
53. Maximum Subarray 2018/5/22 Here DP
54. Spiral Matrix 2018/5/26 Here Four pointers to denote boundaries
55. Jump Game 2018/5/21 Here DP
56. Merge Intervals 2018/5/21 Here Sorting + Greedy
62. Unique Paths 2018/5/28 Here Classical DP
66. Plus One 2018/5/28 Here Advanced bit
69. Sqrt(x) 2018/6/30 Here Binary Search
73. Set Matrix Zeroes 2018/5/25 Here Take use of original matrix space
75. Sort Colors 2018/5/26 Here Two pointer
76. Minimum Window Substring 2018/6/4 Here Same as above
78. Subsets 2018/5/25 Here Backtracking (general way to solve subsets problem)
79. Word Search 2018/5/22 Here DFS
84. Largest Rectangle in Histogram 2018/5/26 Here For each number, find longest range in which it's the minimum with the help of stack
90. Subsets II 2018/5/25 Here Sort + Backtracking
91. Decode Ways 2018/6/4 Here DP, edge cases, care about '0'
94. Binary Tree Inorder Traversal 2018/6/10 Here Do DFS on Binary Tree. Visit left subtree firstly, then visit root, finally visit right subtree
98. Validate Binary Search Tree 2018/6/10 Here From bottom to top. Firstly check left subtree, then check right subtree, finally check root.
101. Symmetric Tree 2018/6/11 Here
  • Recursion.
  • isMirror(left.right, right.left) && isMirror(left.left, right.right) && left.val == right.val
102. Binary Tree Level Order Traversal 2018/6/10 Here Using Queue to do BFS
103. Binary Tree Zigzag Level Order Traversal 2018/6/8 Here Queue + boolean flag
104. Maximum Depth of Binary Tree 2018/6/11 Here BFS using Queue
105. Construct Binary Tree from Preorder and Inorder Traversal 2018/5/28 Here logic behind preorder and inorder
108. Convert Sorted Array to Binary Search Tree 2018/6/11 Here Recursion + Property of BALANCED BST
116. Populating Next Right Pointers in Each Node 2018/6/11 Here
  • Iteration. Do BFS
  • Recursion. connect Left Subtree, then connect right subtree, finally connect right boundary of left subtree with left boundary of right subtree.
121. Best Time to Buy and Sell Stock 2018/5/29 Here DP
122. Best Time to Buy and Sell Stock II 2018/5/29 Here DP
123. Best Time to Buy and Sell Stock III 2018/5/31 Here DP
124. Binary Tree Maximum Path Sum 2018/6/11 Here
  • DP on Tree.
  • Recursive function returns local maximum of path sum which passed through root.
  • We passed a global variable in recursive function, where we possibly update global maximum.
125. Valid Palindrome 2018/6/4 Here Two pointers, one is moving forward while the other is moving backward
127. Word Ladder 2018/6/14 Here Change one character in string to build a new string. BFS
128. Longest Consecutive Sequence 2018/5/21 Here HashMap
130. Surrounded Regions 2018/6/13 Here DFS + Mark out node which's not killed
131. Palindrome Partitioning 2018/6/12 Here DP for checking and finding Palindrome string. Backtracking for partitioning palindrome string.
134. Gas Station 2018/7/12 Here Greedy. We need to find the peak of fuel "need" (the need of i is cost[i]-gas[i]). If we can run around a circuit successfully, the start point should be the next index of "need" peek. But if at the end the accumulated need is larger than 0, we cannot complete a circuit.
136. Single Number 2018/7/11 Here XOR
137. Single Number II 2018/7/12 Here Bitwise + State Machine
138. Copy List with Random Pointer 2018/6/2 Here Firstly, copy label and put new generated node right behind original node; Then copy random pointer; Finally, extract copied nodes and reset original list
139. Word Break 2018/7/12 Here DP: DP[i] denotes whether we can break s[0:i-1]
141. Linked List Cycle 2018/6/1 Here Two pointers, one moves forward by 2 steps while the other moves forward by 1 step.
148. Sort List 2018/6/2 Here Merge Sort
149. Max Points on a Line 2018/7/8 Here
  • 1. Use HashMap to store "slope"
  • 2. Normalized diffY and diffX based on their GCD. And generated a String as key in the HashMap, inorder to deal with Double's precision problem.
150. Evaluate Reverse Polish Notation 2018/7/11 Here Using Stack to store number we met. Each time we meet an operator, We do a computation on the top two numbers, then we push the result back to the top of stack.
152. Maximum Product Subarray 2018/5/21 Here DP
155. Min Stack 2018/7/9 Here Each time we push a new item, we need to push current Minimal value alongside.
160. Intersection of Two Linked Lists 2018/6/1 Here Two pointers, finding entry point of the circular list
162. Find Peak Element 2018/5/24 Here Binary Search
163. Missing Ranges 2018/5/23 Here Iteration, edge cases
166. Fraction to Recurring Decimal 2018/7/6 Here 1. Using recursion to compute decimal 2. Using hashmap to deal with infinite circulating decimal
169. Majority Element 2018/5/21 Here Candidate + Count
188. Best Time to Buy and Sell Stock IV 2018/5/31 Here DP
189. Rotate Array 2018/5/23 Here General way to rotate array (3 reverse)
190. Reverse Bits 2018/6/18 Here
  • Iteration + Bit Operation
  • Divide & Conquer
198. House Robber 2018/7/8 Here Easy DP
200. Number of Islands 2018/7/9 Here Two solutions:
  • 1. Using DFS to "clear" a island when we meet an new island. However, this solution requires us to modify the input grid map
  • 2. If we are not allowed to modify grid map, Get help from Union Find
202. Happy Number 2018/7/12 Here Iteration + Using HashSet to record number we've met.
206. Reverse Linked List 2018/6/1 Here Two ways: 1. recursion; 2. pinpoint tail, and then continuously move head to the next of tail, until tail is head.
207. Course Schedule 2018/6/13 Here Topo sort
208. Implement Trie (Prefix Tree) 2018/6/21 Here Fundamental implementation of Trie
210. Course Schedule II 2018/6/13 Here Topo Sort
212. Word Search II 2018/6/19 Here Trie Tree stores dictionary, DFS searches words in mtx
215. Kth Largest Element in an Array 2018/6/21 Here
  • Priority Queue
  • Quick select (partition in QuickSort)
217. Contains Duplicate 2018/5/29 Here 1. Sorting; 2. HashSet
224. Basic Calculator 2018/6/7 Here
  • Recursion
  • Or using math logics
227. Basic Calculator II 2018/6/7 Here Stack, reverse polish expression
230. Kth Smallest Element in a BST 2018/6/10 Here Do Binary Search on BST. It's just like do DFS on BST, so that we can visit nodes in order. And we record how many nodes we have visited, and once we visited Kth node, we return it.
234. Palindrome Linked List 2018/5/22 Here Two Pointer, find half point in Linkedlist
236. Lowest Common Ancestor of a Binary Tree 2018/6/11 Here Recursion + From Bottom to top
237. Delete Node in a Linked List 2018/6/1 Here Set node's value to next node's value. Like the way we use to delete a value in the array
242. Valid Anagram 2018/7/6 Here
    Two solutions:
  • 1. Sort two Strings, and then compare them.
  • 2. Using Array to store appearances of each character
251. Flatten 2D Vector 2018/6/12 Here Index to show we're at the Col-th element in the Row-th list. When moving forward col and row, we need to care about empty list
253. Meeting Rooms II 2018/7/3 Here 1st solution: Using TreeMap; 2nd Solution: using priority queue
268. Missing Number 2018/5/23 Here Using index space!
269. Alien Dictionary 2018/6/18 Here Topo Sort
283. Move Zeroes 2018/5/22 Here Two Pointer
285. Inorder Successor in BST 2018/6/10 Here do recursion along with passing a upperRight node
287. Find the Duplicate Number 2018/5/22 Here Binary Search (Brilliant!)
295. Find Median from Data Stream 2018/6/22 Here Two PriorityQueues: maxHeap + minHeap
297. Serialize and Deserialize Binary Tree 2018/6/12 Here Borrow ideas from Heap
300. Longest Increasing Subsequence 2018/6/14 Here Build LIS. Use binary search to find the lowerBoundIdx in the LIS when we meet an new number
309. Best Time to Buy and Sell Stock with Cooldown 2018/5/31 Here DP
315. Count of Smaller Numbers After Self 2018/6/13 Here Get helps from Merge Sort
322. Coin Change 2018/6/12 Here DP
328. Odd Even Linked List 2018/6/2 Here put nodes in one list to another list
329. Longest Increasing Path in a Matrix 2018/6/18 Here DFS + Memoization
334. Increasing Triplet Subsequence 2018/6/20 Here Borrow Idea from 300. Longest Increasing Subsequence. If one sequence contains Increasing Triple Subsequence, it means this array contains at least one increasing subsequence with 3 numbers.
340. Longest Substring with At Most K Distinct Characters 2018/6/4 Here
  • Two pointers to delimit substring;
  • HashMap to record how many different character appear in substring, and record number of appearances of each character
344. Reverse String 2018/6/5 Here Easiest
378. Kth Smallest Element in a Sorted Matrix 2018/6/12 Here Two ways:
  • PriorityQueue: Put element into PQ, along with each element, we also record their coordinates(x, y)
  • Binary Search: Just like the solution of 41. First Missing Positive, We do binary search on values space of elements in matrix
380. Insert Delete GetRandom O(1) 2018/5/29 Here ArrayList + HashMap + record index in hashmap
381. Insert Delete GetRandom O(1) - Duplicates allowed 2018/5/30 Here ArrayList + HashMap + record indexes using linkedlist
384. Shuffle an Array 2018/7/1 Here How to shuffle an array? For each index i from array.length-1 to 0, you can find an random number j ranged from [0, i], then swap array[i] and array[j]
387. First Unique Character in a String 2018/6/4 Here Using array to store appearance of lowercase character
454. 4Sum II 2018/6/13 Here Recall HashMap way in 2Sum. Turn 4Sum to 2Sum. See A[i]+B[j] as one, and C[k]+D[l] as the other.
772. Basic Calculator III 2018/6/7 Here
  • Recursion to solve embedded expression closed by '()'
  • Stack to solve operators with diffrent priority

Array

Question Done Date Code Note
11. Container With Most Water 2018/5/21 Here Two pointer
16. 3Sum Closest 2018/5/21 Here Sorting
41. First Missing Positive 2018/5/21 Here Using Index space
238. Product of Array Except Self 2018/5/21 Here DP
169. Majority Element 2018/5/21 Here Candidate + Count
152. Maximum Product Subarray 2018/5/21 Here DP
56. Merge Intervals 2018/5/21 Here Sorting + Greedy
55. Jump Game 2018/5/21 Here DP
153. Find Minimum in Rotated Sorted Array 2018/5/21 Here Binary Search
154. Find Minimum in Rotated Sorted Array II 2018/5/21 Here Binary Search
128. Longest Consecutive Sequence 2018/5/21 Here HashMap
33. Search in Rotated Sorted Array 2018/5/22 Here Binary Search
81. Search in Rotated Sorted Array II 2018/5/22 Here Binary Search
53. Maximum Subarray 2018/5/22 Here DP
283. Move Zeroes 2018/5/22 Here Two Pointer
79. Word Search 2018/5/22 Here DFS
287. Find the Duplicate Number 2018/5/22 Here Binary Search (Brilliant!)
268. Missing Number 2018/5/23 Here Using index space!
163. Missing Ranges 2018/5/23 Here Iteration, edge cases
189. Rotate Array 2018/5/23 Here General way to rotate array (3 reverse)
162. Find Peak Element 2018/5/24 Here Binary Search
78. Subsets 2018/5/25 Here Backtracking (general way to solve subsets problem)
90. Subsets II 2018/5/25 Here Sort + Backtracking
26. Remove Duplicates from Sorted Array 2018/5/25 Here Two pointers
73. Set Matrix Zeroes 2018/5/25 Here Take use of original matrix space
84. Largest Rectangle in Histogram 2018/5/26 Here For each number, find longest range in which it's the minimum with the help of stack
75. Sort Colors 2018/5/26 Here Two pointer
34. Search for a Range 2018/5/26 Here Binary search
54. Spiral Matrix 2018/5/26 Here Four pointers to denote boundaries
48. Rotate Image 2018/5/27 Here Four pointer to denote four points on which we need to operate
105. Construct Binary Tree from Preorder and Inorder Traversal 2018/5/28 Here logic behind preorder and inorder
66. Plus One 2018/5/28 Here Advanced bit
1. Two Sum 2018/5/28 Here Two ways: 1. sorting + two pointers; 2. HashMap
15. 3Sum 2018/5/28 Here Classical Sorting + two pointers
62. Unique Paths 2018/5/28 Here Classical DP
217. Contains Duplicate 2018/5/29 Here 1. Sorting; 2. HashSet
121. Best Time to Buy and Sell Stock 2018/5/29 Here DP
122. Best Time to Buy and Sell Stock II 2018/5/29 Here DP
123. Best Time to Buy and Sell Stock III 2018/5/31 Here DP
188. Best Time to Buy and Sell Stock IV 2018/5/31 Here DP
309. Best Time to Buy and Sell Stock with Cooldown 2018/5/31 Here DP
380. Insert Delete GetRandom O(1) 2018/5/29 Here ArrayList + HashMap + record index in hashmap
381. Insert Delete GetRandom O(1) - Duplicates allowed 2018/5/30 Here ArrayList + HashMap + record indexes using linkedlist
689. Maximum Sum of 3 Non-Overlapping Subarrays 2018/6/1 Here DP, variance of Best Time to Buy and Sell Stocks
251. Flatten 2D Vector 2018/6/12 Here Index to show we're at the Col-th element in the Row-th list. When moving forward col and row, we need to care about empty list
131. Palindrome Partitioning 2018/6/12 Here DP for checking and finding Palindrome string. Backtracking for partitioning palindrome string.
315. Count of Smaller Numbers After Self 2018/6/13 Here Get helps from Merge Sort
454. 4Sum II 2018/6/13 Here Recall HashMap way in 2Sum. Turn 4Sum to 2Sum. See A[i]+B[j] as one, and C[k]+D[l] as the other.
300. Longest Increasing Subsequence 2018/6/14 Here Build LIS. Use binary search to find the lowerBoundIdx in the LIS when we meet an new number
269. Alien Dictionary 2018/6/18 Here Topo Sort
334. Increasing Triplet Subsequence 2018/6/20 Here Borrow Idea from 300. Longest Increasing Subsequence. If one sequence contains Increasing Triple Subsequence, it means this array contains at least one increasing subsequence with 3 numbers.
215. Kth Largest Element in an Array 2018/6/21 Here
  • Priority Queue
  • Quick select (partition in QuickSort)
845. Longest Mountain in Array 2018/6/25 Here Two Pointers way:
  • Firstly find the peak (be careful about the platform, which is not the actual peak)
  • Secondly find the bottom
719. Find K-th Smallest Pair Distance 2018/6/25 Here Binary Search on space of possible answers: We can know minimal distance and maximal distance from sorted array, then binary search to find k-th distance.
384. Shuffle an Array 2018/7/1 Here How to shuffle an array? For each index i from array.length-1 to 0, you can find an random number j ranged from [0, i], then swap array[i] and array[j]
253. Meeting Rooms II 2018/7/3 Here 1st solution: Using TreeMap; 2nd Solution: using priority queue
198. House Robber 2018/7/8 Here Easy DP
134. Gas Station 2018/7/12 Here Greedy. We need to find the peak of fuel "need" (the need of i is cost[i]-gas[i]). If we can run around a circuit successfully, the start point should be the next index of "need" peek. But if at the end the accumulated need is larger than 0, we cannot complete a circuit.

Linked List

Question Done Date Code Note
234. Palindrome Linked List 2018/5/22 Here Two Pointer, find half point in Linkedlist
21. Merge Two Sorted Lists 2018/5/22 Here Two Pointer, Merge sort
19. Remove Nth Node From End of List 2018/6/1 Here two pointers
2. Add Two Numbers 2018/6/1 Here two pointers, advacend bit
160. Intersection of Two Linked Lists 2018/6/1 Here Two pointers, finding entry point of the circular list
141. Linked List Cycle 2018/6/1 Here Two pointers, one moves forward by 2 steps while the other moves forward by 1 step.
142. Linked List Cycle II 2018/7/3 Here
  • Firstly, use fast-pointer & slow-pointer to find whether there are cycle in linkedlist
  • Then we find entry of that cycle by:
    • Start by head pointer and current slow pointer, they move forward by one step each time.
    • The node where they meet each other is the entry of cycle.
237. Delete Node in a Linked List 2018/6/1 Here Set node's value to next node's value. Like the way we use to delete a value in the array
206. Reverse Linked List 2018/6/1 Here Two ways: 1. recursion; 2. pinpoint tail, and then continuously move head to the next of tail, until tail is head.
148. Sort List 2018/6/2 Here Merge Sort
328. Odd Even Linked List 2018/6/2 Here put nodes in one list to another list
23. Merge k Sorted Lists 2018/6/2 Here Priority Queue
138. Copy List with Random Pointer 2018/6/2 Here Firstly, copy label and put new generated node right behind original node; Then copy random pointer; Finally, extract copied nodes and reset original list
143. Reorder List 2018/6/22 Here
  • Find middle node and tail node
  • Reverse list from middle node to tail
  • merge two lists: one is from head to half, the other is leading by tail.
147. Insertion Sort List 2018/6/23 Here Insertion Sort
24. Swap Nodes in Pairs 2018/6/23 Here Operations on Linked List: Swap two nodes
92. Reverse Linked List II 2018/7/1 Here Firstly determine start point and end point. Then reverse

String

Question Done Date Code Note
408. Valid Word Abbreviation 2018/6/3 Here convert string to char array; Two pointers; Extract numeric string and convert it to number
125. Valid Palindrome 2018/6/4 Here Two pointers, one is moving forward while the other is moving backward
91. Decode Ways 2018/6/4 Here DP, edge cases, care about '0'
387. First Unique Character in a String 2018/6/4 Here Using array to store appearance of lowercase character
13. Roman to Integer 2018/6/4 Here Math logic
340. Longest Substring with At Most K Distinct Characters 2018/6/4 Here
  • Two pointers to delimit substring;
  • HashMap to record how many different character appear in substring, and record number of appearances of each character
76. Minimum Window Substring 2018/6/4 Here Same as above
3. Longest Substring Without Repeating Characters 2018/6/4 Here Two pointers + Boolean array recording character appearing in s[slow:fast]
344. Reverse String 2018/6/5 Here Easiest
49. Group Anagrams 2018/6/5 Here HashMap; Firstly sort the string
14. Longest Common Prefix 2018/6/5 Here Pointer to specify index we're at + vertical iteration and comparation
28. Implement strStr() 2018/6/5 Here Using java built-in substring() and equals()
20. Valid Parentheses 2018/6/6 Here Stack
38. Count and Say 2018/6/6 Here Operation of StringBuilder
8. String to Integer (atoi) 2018/6/6 Here Edge cases: 1. leading blanks; 2. '+' or '-'; 3. Integer overflow
5. Longest Palindromic Substring 2018/6/6 Here Two pointers
22. Generate Parentheses 2018/6/6 Here Backtracking
17. Letter Combinations of a Phone Number 2018/6/6 Here Backtracking
44. Wildcard Matching 2018/6/7 Here DP
10. Regular Expression Matching 2018/6/7 Here DP
224. Basic Calculator 2018/6/7 Here
  • Recursion
  • Or using math logics
227. Basic Calculator II 2018/6/7 Here Stack, reverse polish expression
772. Basic Calculator III 2018/6/7 Here
  • Recursion to solve embedded expression closed by '()'
  • Stack to solve operators with diffrent priority
844. Backspace String Compare 2018/6/25 Here Go from tail to head. If meet '#', then skip previous non-'#' character
242. Valid Anagram 2018/7/6 Here
    Two solutions:
  • 1. Sort two Strings, and then compare them.
  • 2. Using Array to store appearances of each character
139. Word Break 2018/7/12 Here DP: DP[i] denotes whether we can break s[0:i-1]

Tree

Question Done Date Code Note
105. Construct Binary Tree from Preorder and Inorder Traversal 2018/5/28 Here logic behind preorder and inorder
103. Binary Tree Zigzag Level Order Traversal 2018/6/8 Here Queue + boolean flag
102. Binary Tree Level Order Traversal 2018/6/10 Here Using Queue to do BFS
230. Kth Smallest Element in a BST 2018/6/10 Here Do Binary Search on BST. It's just like do DFS on BST, so that we can visit nodes in order. And we record how many nodes we have visited, and once we visited Kth node, we return it.
94. Binary Tree Inorder Traversal 2018/6/10 Here Do DFS on Binary Tree. Visit left subtree firstly, then visit root, finally visit right subtree
285. Inorder Successor in BST 2018/6/10 Here do recursion along with passing a upperRight node
98. Validate Binary Search Tree 2018/6/10 Here From bottom to top. Firstly check left subtree, then check right subtree, finally check root.
101. Symmetric Tree 2018/6/11 Here
  • Recursion.
  • isMirror(left.right, right.left) && isMirror(left.left, right.right) && left.val == right.val
104. Maximum Depth of Binary Tree 2018/6/11 Here BFS using Queue
108. Convert Sorted Array to Binary Search Tree 2018/6/11 Here Recursion + Property of BALANCED BST
116. Populating Next Right Pointers in Each Node 2018/6/11 Here
  • Iteration. Do BFS
  • Recursion. connect Left Subtree, then connect right subtree, finally connect right boundary of left subtree with left boundary of right subtree.
235. Lowest Common Ancestor of a Binary Search Tree 2018/6/11 Here Recursion + Property of BST
236. Lowest Common Ancestor of a Binary Tree 2018/6/11 Here Recursion + From Bottom to top
124. Binary Tree Maximum Path Sum 2018/6/11 Here
  • DP on Tree.
  • Recursive function returns local maximum of path sum which passed through root.
  • We passed a global variable in recursive function, where we possibly update global maximum.
297. Serialize and Deserialize Binary Tree 2018/6/12 Here Borrow ideas from Heap
127. Word Ladder 2018/6/14 Here Change one character in string to build a new string. BFS
208. Implement Trie (Prefix Tree) 2018/6/21 Here Fundamental implementation of Trie

Graph

Question Done Date Code Note
207. Course Schedule 2018/6/13 Here Topo sort
210. Course Schedule II 2018/6/13 Here Topo Sort

Math

Question Done Date Code Note
190. Reverse Bits 2018/6/18 Here
  • Iteration + Bit Operation
  • Divide & Conquer
836. Rectangle Overlap 2018/6/25 Here Determined by relationship either between rec1's left-bottom and rec2's right-top, or between rec1's right-top and rec2's left-bottom
69. Sqrt(x) 2018/6/30 Here Binary Search
166. Fraction to Recurring Decimal 2018/7/6 Here 1. Using recursion to compute decimal 2. Using hashmap to deal with infinite circulating decimal
149. Max Points on a Line 2018/7/8 Here
  • 1. Use HashMap to store "slope"
  • 2. Normalized diffY and diffX based on their GCD. And generated a String as key in the HashMap, inorder to deal with Double's precision problem.
150. Evaluate Reverse Polish Notation 2018/7/11 Here Using Stack to store number we met. Each time we meet an operator, We do a computation on the top two numbers, then we push the result back to the top of stack.
136. Single Number 2018/7/11 Here XOR
137. Single Number II 2018/7/12 Here Bitwise + State Machine
202. Happy Number 2018/7/12 Here Iteration + Using HashSet to record number we've met.

Matrix

Question Done Date Code Note
378. Kth Smallest Element in a Sorted Matrix 2018/6/12 Here Two ways:
  • PriorityQueue: Put element into PQ, along with each element, we also record their coordinates(x, y)
  • Binary Search: Just like the solution of 41. First Missing Positive, We do binary search on values space of elements in matrix
130. Surrounded Regions 2018/6/13 Here DFS + Mark out node which's not killed
329. Longest Increasing Path in a Matrix 2018/6/18 Here DFS + Memoization
212. Word Search II 2018/6/19 Here Trie Tree stores dictionary, DFS searches words in mtx
200. Number of Islands 2018/7/9 Here Two solutions:
  • 1. Using DFS to "clear" a island when we meet an new island. However, this solution requires us to modify the input grid map
  • 2. If we are not allowed to modify grid map, Get help from Union Find

Design

Question Done Date Code Note
295. Find Median from Data Stream 2018/6/22 Here Two PriorityQueues: maxHeap + minHeap
155. Min Stack 2018/7/9 Here Each time we push a new item, we need to push current Minimal value alongside.

leetcode-1's People

Contributors

qinshuxiao avatar

Watchers

James Cloos avatar Wangshu Zhang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.