LeetCode Record Summary

first 300 round one

Posted by Clover on May 18, 2018

Record of Submissions

# Name & Solution Difficulty Hint
1 Two Sum Easy (hashMap)
3 Longest Substring Without Repeating Characters Medium slow and fast, to the new position (pointer)
4 Median of Two Sorted Arrays Hard delete the smaller half (binary)
5 Longest Palindromic Substring Medium Even or odd length (substr)
10 Regular Expression Matching Hard dp + dfs, similar to the wildcard, but * is only same as presending (DFS)
12 Integer to Roman Medium list all the possible sites (math)
13 Roman to Integer Easy if left is smaller than right, than use the value of right - left (math)
15 3Sum Medium (pointer)
16 3Sum Closest Medium first theree numbers as inital sum (pointer)
17 Letter Combinations of a Phone Number Medium use hashmap to store number and chars (DFS)
18 4Sum Medium one addition + 3sum (pointer)
21 Merge Two Sorted Lists Easy move the smaller node (linked list)
23 Merge k Sorted Lists Hard 3 methods: merge in order/ heap/ merge two by two (Linked list)
26 Remove Duplicates from Sorted Array Easy (pointer)
28 Implement strStr() Easy left the length of needle at the end (substr)
31 Next Permutation Medium right side is descending order and reverse (pointer)
33 Search in Rotated Sorted Array Medium two parts ascending (binary)
34 Search for a Range Medium first occurence + last occurence (binary)
35 Search Insert Position Easy Last occurence, move the left first (binary)
39 Combination Sum Medium repeatly use elements (DFS)
40 Combination Sum II Medium no duplicate like subset ii (DFS)
44 Wildcard Matching Hard seperate star, question sign and DP record (DFS)
46 Permutations Medium different from subset, i is from 0 not from start (DFS)
47 Permutations II Medium check the duplications, boolean array (DFS)
50 Pow(x, n) Medium x^n = x^(n/2) * x^(n/2) (binary)
51 N-Queens Hard use Arraylist to record the col value and row index (DFS)
52 N-Queens II Hard easier version of n-queen, only count distinct number (DFS)
53 Maximum Subarray Easy find the Math.max(current value, accumulation of previous sum) (dp)
56 Merge Intervals Medium sort the interval.start by implementing compare function(sort)
57 Insert Interval Hard compare the last.end and item.start; do the combination if necessary (sort)
60 Permutation Sequence Medium find index k/factor and update k = k%factor (math)
67 Add Binary Easy add the carry to the sum for next step (math)
69 Sqrt(x) Easy Last occurence, left move first (binary)
70 Climbing Stairs Easy the methods for current time = sum of methods for previous two times (dp)
74 Search a 2D Matrix Medium transfer from matrix into a array (binary)
75 Sort Colors Medium three points, four blocks (pointer)
77 Combinations Medium k is the size of each list (DFS)
78 Subsets Medium add, dfs and remove (DFS)
79 Word Search Medium i +/- 1 and j +/- 1 keep the order, i together and j together (DFS)
81 Search in Rotated Sorted Array II Medium compare value at left and mid sites and if same just left++ to remove the duplications (binary)
83 Remove Duplicates from Sorted List Easy one pointer node (linked list)
86 Partition List Medium two dummy heads, and concate (Linked List)
88 Merge Sorted Array Easy from the end to the beginning (pointer)
90 Subsets II Medium for loop to keep each answer directly (DFS)
94 Binary Tree Inorder Traversal Medium if use iterative way, consider cur node and stack is empty (DFS)
98 Validate Binary Search Tree Medium long type (DFS)
100 Same Tree Easy every node should be same (DFS)
101 Symmetric Tree Easy symmtric by the root (DFS)
102 Binary Tree Level Order Traversal Medium BFS by level (BFS)
103 Binary Tree Zigzag Level Order Traversal Medium traverse binary tree layer by layer different direction (BFS)
104 Maximum Depth of Binary Tree Easy 1+max(l,r) (DFS)
105 Construct Binary Tree from Preorder and Inorder Traversal Medium find the root index in inorder (DFS)
106 Construct Binary Tree from Inorder and Postorder Traversal Medium find the root in inorder (DFS)
107 Binary Tree Level Order Traversal II Easy traverse layer by layer, reverse (BFS)
108 Convert Sorted Array to Binary Search Tree Easy two pointers (tree)
109 Convert Sorted List to Binary Search Tree Medium modifed find linked list middle (DFS)
110 Balanced Binary Tree Easy from lower to higher -1 (DFS)
111 Minimum Depth of Binary Tree Easy left+right+1, cannot be 0 (DFS)
112 Path Sum Easy reduced the current node.val (DFS)
114 Flatten Binary Tree to Linked List Medium record the right child first (DFS)
121 Best Time to Buy and Sell Stock Easy update the min and the max profit (dp)
124 Binary Tree Maximum Path Sum Hard return half and connect together (DFS)
125 Valid Palindrome Easy remove the invalid from two ends to the middle (substr)
126 Word Ladder II Hard hashmap has a set as value to store the words one step away from cur word (BFS+DFS)
127 Word Ladder Medium change each char in the word to see in the dict, layer by layer (BFS)
130 Surrounded Regions Medium up to down, left to right (BFS)
131 Palindrome Partitioning Medium substring to partition (DFS)
133 Clone Graph Medium bfs without layers (BFS)
139 Word Break Medium true connect cut points (dp)
140 Word Break II Hard the order is reversed after dfs (DFS)
141 Linked List Cycle Easy slow & fast pointer (linked list)
142 Linked List Cycle II Medium slow and fast pointer (linked list)
144 Binary Tree Preorder Traversal Medium reverse the order, so right move in first for iterative method (DFS)
145 Binary Tree Postorder Traversal Hard left, right, root from root, right, left (DFS)
146 LRU Cache Hard if existed, remove and append; not existed, node new or update and append (design)
148 Sort List Medium merge sort and quick sort (sort)
152 Maximum Product Subarray Medium if negative, change max and min value (dp)
153 Find Minimum in Rotated Sorted Array Medium smallest one is in the right ascending part (binary)
154 Find Minimum in Rotated Sorted Array II Medium just compare the mid and right, and remove the duplications by right– (binary)
155 Min Stack Easy offer the min value of global min and current value to the minStack (design)
162 Find Peak Element Medium nums[mid] < nums[mid + 1] (binary)
167 Two Sum II - Input array is sorted Easy (pointer)
168 Excel Sheet Column Title Easy ‘A’ + n - 1 to get the new char (math)
170 Two Sum III - Data structure design Easy list can change length (hashMap)
171 Excel Sheet Column Number Easy nums on the last step * 26 + current number (math)
173 Binary Search Tree Iterator Medium find the smallest left first and then right, inorder (tree)
198 House Robber Easy f(k) = Math.max(f(k-2) + x, f(k-1)) (dp)
200 Number of Islands Medium coordinate, change 1 to 0 after traverse (BFS)
205 Isomorphic Strings Easy match char to char by hashmap (hashmap)
207 Course Schedule Medium topological sort, result size == numCourses (BFS)
208 Implement Trie (Prefix Tree) Medium if end return true, use c-‘a’ to determine the index in the array (tree)
209 Minimum Size Subarray Sum Medium move right pointer first until >= s, then move left pointer to reduce the size (pointer)
210 Course Schedule II Medium reverse the order of prerequisites (BFS)
212 Word Search II Hard use TrieNode, after find one word, put that end to null (DFS)
215 Kth Largest Element in an Array Medium quick selection (sort)
216 Combination Sum III Medium only 1~9 are needed (DFS)
225 Implement Stack using Queues Easy deliver all elements (except the last element) to another queue and then swap two queues (design)
230 Kth Smallest Element in a BST Medium inorder traverse (DFS)
231 Power of Two Easy n&(n-1) trick (math)
232 Implement Queue using Stacks Easy one stack is for storage, and another stack is for poll out (design)
235 Lowest Common Ancestor of a Binary Search Tree Easy both not null return root (DFS)
236 Lowest Common Ancestor of a Binary Tree Medium not sure existed (DFS)
240 Search a 2D Matrix II Medium from the lower left (pointer)
252 Meeting Rooms Easy sort by Arrays.sort and determine whether the first.end < second.start (sort)
253 Meeting Rooms II Medium like 252, but add a minheap to control the end and merge intersections (sort)
257 Binary Tree Paths Easy a new string each level (DFS)
259 3Sum Smaller Medium Don’t move right, but count the interval of left and right (pointer)
261 Graph Valid Tree Medium construct graph and bfs (BFS)
263 Ugly Number Easy divided by 2,3,5 repeatedly (math)
264 Ugly Number II Medium index times factor and compare each possible products (dp)
266 Palindrome Permutation Easy there should be no additional or only 1 additional char (hash table)
267 Palindrome Permutation II Medium half even number permutations, symmetric (DFS)
268 Missing Number Easy add maxLen = nums.length to do ^ (math)
269 Alien Dictionary Hard construct the map (BFS)
270 Closest Binary Search Tree Value Easy the property of BST (tree)
272 Closest Binary Search Tree Value II Hard two stack, two pointers (tree)
278 First Bad Version Easy first occurance, move the right first (binary)
283 Move Zeroes Easy slow records ans (pointer)
285 Inorder Successor in BST Medium find the target and than to the right child and left first (tree)
287 Find the Duplicate Number Medium similar to the cycle in linked list(pointer)
290 Word Pattern Easy match char and string (hashmap)
291 Word Pattern II Hard DFS is boolean and use map and set to match char and string (DFS)
295 Find Median from Data Stream Hard smallHalf uses a maxHeap; largeHalf uses a minHeap (design)
297 Serialize and Deserialize Binary Tree Hard print binary tree layer by layer (BFS)
300 Longest Increasing Subsequence Medium First occurence (binary)
301 Remove Invalid Parentheses Hard substring to remove the current char (DFS)
346 Moving Average from Data Stream Easy sliding window by the queue (design)
347 Top K Frequent Elements Medium use hashmap to count the frequency (pq)
349 Intersection of Two Arrays Easy sort and move two pointers (pointer)
350 Intersection of Two Arrays II Easy if sorted use two pointers (hashmap)
378 Kth Smallest Element in a Sorted Matrix Medium use a coor to save x, y and value; then put one column into pq (pq)
380 Insert Delete GetRandom O(1) Medium import java.util.Random, arrayList swap with the last item and delete (design)
381 Insert Delete GetRandom O(1) - Duplicates allowed Hard copy the last element to replace the target, and remove the last item; also update the position in the map (design)
387 First Unique Character in a String Easy use int[256] to record time of occurance (hashtable)
409 Longest Palindrome Easy The longest could be odd, so even + 1 (substr)
450 Delete Node in a BST Medium find the smallest on right child (DFS)
516 Longest Palindromic Subsequence Medium 2d-dp as #5 (substr)
653 Two Sum IV - Input is a BST Easy same as two sum (pointer)
658 Find K Closest Elements Medium last occurence (binary)
680 Valid Palindrome II Easy (pointer)
681 Next Closest Time Medium convert to miniute from integer (DFS)
697 Degree of an Array Easy use three hashmap to record count, left, and right index (hashmap)

Last Update: 06/18/2018