I will use this repository to make notes for leetcode solutions and classify the problems by different topics.
Total solved: 108
ID | Difficulty | Tags | Solution | Similar Problem |
---|---|---|---|---|
206 | Easy | Linked List | Reverse Linked List | |
138 | Medium | LinkedList, Dictionary | Copy List with Random Pointer | |
419 | Medium | Two dimentional array | Battleships in a Board | |
273 | Hard | Math, string | Integer to English Words | |
54 | Medium | Array | Spiral Matrix | |
171 | Easy | Math | Excel Sheet Column Number | 168 |
235 | Medium | BST | Lowest Common Ancestor of a Binary Search Tree | |
200 | Medium | BFS, DFS | Number of Islands | |
88 | Easy | Two pointers | Merge Sorted Array | |
236 | Medium | Tree | Lowest Common Ancestor of a Binary Tree | |
48 | Medium | Array | Rotate Image | |
445 | Medium | LinkedList, Stack | Add Two Numbers II | |
268 | Easy | Array, Bit Manipulation | Missing Number | |
1 | Easy | Array, Hash Table (Dictionary) | Two Sum | |
186 | Medium | String | Reverse Words in a String II | |
53 | Easy | Dynamic Programming, Divide and Conquer | Maximum Subarray | |
103 | Medium | Tree, BFS, Stack | Binary Tree Zigzag Level Order Traversal | |
151 | Medium | String | Reverse Words in a String | |
116 | Medium | Tree, DFS | Populating Next Right Pointers in Each Node | |
75 | Medium | Array, Two pointers, Sort | Sort Colors | |
73 | Medium | Array | Set Matrix Zeroes | |
238 | Medium | Array | Product of Array Except Self | |
237 | Easy | Linked List | Delete Node in a Linked List | |
121 | Easy | Array, Dynamic Programming | Best Time to Buy and Sell Stock | |
168 | Easy | Math, char | Excel Sheet Column Title | 171 |
141 | Easy | Two pointers, Linked List | Linked List Cycle | |
13 | Easy | String, Math | Roman to Integer | |
98 | Medium | Tree, DFS | Validate Binary Search Tree | |
117 | Medium | Tree | Populating Next Right Pointers in Each Node II | |
21 | Easy | Linked List | Merge Two Sorted Lists | |
20 | Easy | Stack, String | Valid Parentheses | |
8 | Medium | Math, String | String to Integer (atoi) | |
2 | Medium | LinkedList, Math | Add Two Numbers | |
33 | Medium | Binary Search, Array | Search in Rotated Sorted Array | |
232 | Easy | Stack, Design | Implement Queue using Stacks | |
153 | Medium | Binary Search, Array | Find Minimum in Rotated Sorted Array | |
24 | Medium | Linked List | Swap Nodes in Pairs | |
173 | Medium | Tree, Stack, Degine | Binary Search Tree Iterator | |
215 | Medium | Divide and Conquer | Kth Largest Element in an Array | |
106 | Medium | Tree, DFS, Array | Construct Binary Tree from Inorder and Postorder Traversal |
ID | Difficulty | Tags | Solution | Similar Problem |
---|---|---|---|---|
2 | Medium | LinkedList, Math | Add Two Numbers | |
5 | Medium | string | Longest Palindromic Substring | |
11 | Medium | Array, Two pointers | Container With Most Water | |
13 | Easy | String, Math | Roman to Integer | |
14 | Easy | String | Longest Common Prefix | |
15 | Medium | Array, Two pointers | 3Sum | |
17 | Medium | string, backtracking | Letter Combinations of a Phone Number | |
19 | Medium | LinkedList, Two Pointers | Remove Nth Node From End of List | |
22 | Medium | BackTracking, DFS | Generate Parentheses | |
38 | Easy | String | Count and Say | |
53 | Easy | Dynamic Programming, Divide and Conquer | Maximum Subarray | |
66 | Easy | Array, Math | Plus One | 67 |
67 | Easy | String, Math | Add Binary | |
69 | Easy | Binary Search, Math | Sqrt(x) | 367 |
70 | Easy | Dynamic Programming | Climbing Stairs | |
101 | Easy | Tree | Symmetric Tree | |
108 | Easy | Tree, DFS | Convert Sorted Array to Binary Search Tree | |
118 | Easy | Array, Math | Pascal's Triangle | |
121 | Easy | Array, Dynamic Programming | Best Time to Buy and Sell Stock | |
122 | Easy | Array | Best Time to Buy and Sell Stock II | |
155 | Easy | Stack, Design | Min Stack | |
160 | Easy | LinkedList | Intersection of Two Linked Lists | |
169 | Easy | Dictionary | Majority Element | |
171 | Easy | Math | Excel Sheet Column Number | 168 |
172 | Easy | Math | Factorial Trailing Zeroes | |
189 | Easy | Arrays, Two pointers | Rotate Array | |
198 | Easy | Dynamic Programming | House Robber | |
202 | Easy | Math, HashSet | Happy Number | |
204 | Easy | Math, Array | Count Primes | |
217 | Easy | Dictionary | Contains Duplicate | |
219 | Easy | HashMap, HashSet, Sliding window | Contains Duplicate II | |
268 | Easy | Array, Bit Manipulation | Missing Number | |
344 | Easy | Two pointers | Reverse String | |
349 | Easy | Two pointers, HashMap(Dictionary) | Intersection of Two Arrays | |
350 | Easy | Two pointers, HashMap(Dictionary) | Intersection of Two Arrays II | |
371 | Easy | Bit Manipulation | Sum of Two Integers | |
387 | Easy | HashMap(Dictionary), string | First Unique Character in a String | |
412 | Easy | Math | Fizz Buzz | |
105 | Medium | Tree, DFS, Array | Construct Binary Tree from Preorder and Inorder Traversal |
First, I will start from the very basic and useful part. The Leetcode Course Section, which is selected interview questions aimed for beginners who do not know algorithms or need a refresher. Learn by doing.
ID | Difficulty | Tags | Solution |
---|---|---|---|
26 | Easy | Array, Two Pointers | Remove Duplicates from Sorted Array |
27 | Easy | Array, Two Pointers | Remove Element |
203 | Easy | Linked List | Remove Linked List Elements |
283 | Easy | Array, Two Pointers | Move Zeroes |
167 | Easy | Arra, Two Pointers, Binary Search | Two Sum II - Input array is sorted |
1 | Easy | Array, Hash Table (Dictionary) | Two Sum |
653 | Easy | Binary search Tree, HashSet, BFS, recursion, traverse | Two Sum IV - Input is a BST |
242 | Easy | Hash Table (Dictionary) | Valid Anagram |
438 | Easy | Hash Table (Dictionary), Two pointer, Sub string, Sliding window | Find All Anagrams in a String |
3 | Medium | Hash Table (Dictionary), Two pointer, Sub string, Sliding window | Longest Substring Without Repeating Characters |
28 | Easy | Two pointer, String | Implement strStr() |
459 | Easy | String | Repeated Substring Pattern |
8 | Medium | Math, String | String to Integer (atoi) |
ID | Difficulty | Tags | Solution |
---|---|---|---|
237 | Easy | Linked List | Delete Node in a Linked List |
206 | Easy | Linked List | Reverse Linked List |
234 | Easy | Linked List, Two Pointers | Palindrome Linked List |
9 | Easy | Math | Palindrome Number |
125 | Easy | Two pointers, String | Valid Palindrome |
141 | Easy | Two pointers, Linked List | Linked List Cycle |
142 | Medium | Two pointers, Linked List | Linked List Cycle II |
21 | Easy | Linked List | Merge Two Sorted Lists |
88 | Easy | Two pointers | Merge Sorted Array |
24 | Medium | Linked List | Swap Nodes in Pairs |
ID | Difficulty | Tags | Solution |
---|---|---|---|
104 | Easy | Tree, DFS, BFS level traverse | Maximum Depth of Binary Tree |
110 | Easy | Tree, DFS | Balanced Binary Tree |
111 | Easy | Tree, DFS, Recursion | Minimum Depth of Binary Tree |
100 | Easy | Tree, DFS | Same Tree |
112 | Easy | Tree, DFS | Path Sum |
437 | Easy | Tree, DFS | Path Sum III |
257 | Easy | Tree, DFS | Binary Tree Paths |
98 | Medium | Tree, DFS | Validate Binary Search Tree |
94 | Medium | Tree, Stack | Binary Tree Inorder Traversal |
144 | Medium | Tree, Stack | Binary Tree Preorder Traversal |
145 | Medium | Tree, Stack | Binary Tree Postorder Traversal |
102 | Medium | Tree, Queue, BFS | Binary Tree Level Order Traversal |
-- | Easy | Tree, Recursion | Binary Tree Traversal (Recursion) |
-- | Medium | Tree, Iteration | Binary Tree Traversal (Iteration) |
ID | Difficulty | Tags | Solution |
---|---|---|---|
225 | Easy | Stack, Design | Implement Stack using Queues |
232 | Easy | Stack, Design | Implement Queue using Stacks |
20 | Easy | Stack, String | Valid Parentheses |
102 | Medium | Tree, Queue, Breadth-first Search | Binary Tree Level Order Traversal |
ID | Difficulty | Tags | Solution |
---|---|---|---|
136 | Easy | Bit Manipulation n | Single Number |
190 | Easy | Bit Manipulation n | Reverse Bits |
191 | Easy | Bit Manipulation n | Number of 1 Bits |
231 | Easy | Bit Manipulation n | Power of Two |
342 | Easy | Bit Manipulation n | Power of Four |
ID | Difficulty | Tags | Solution |
---|---|---|---|
278 | Easy | Binary Search | First Bad Version |
374 | Easy | Binary Search | Guess Number Higher or Lower(Current NO C# OJ Support) |
35 | Easy | Binary Search, Array | Search Insert Position |
34 | Medium | Binary Search, Array | Search for a Range |
367 | Medium | Binary Search | Valid Perfect Square |
ID | Difficulty | Tags | Solution |
---|---|---|---|
-- | Medium | Merge sort | MergeSort |
-- | Medium | Quick sort | QuickSort |
21 | Easy | Linked List | Merge Two Sorted Lists |
88 | Easy | Two pointers | Merge Sorted Array |
All the Palindrome problem's core solution is check if reverse == origin. A efficient way is to compare reverse the sencond half, and check if FirstHalf(origin) == SecondHalf(reversed). For int, core solution is:
while (x > rev) {
rev = rev * 10 + x % 10;
x = x / 10;
}
return (x == rev || x == rev / 10);
For string, core solution is:
while (left <= right){
if (char.ToLower(leftChar)
!= char.ToLower(rightChar)){
return false;
}
left++;
right--;
}
return true;
ID | Difficulty | Tags | Solution |
---|---|---|---|
9 | Easy | Math | Palindrome Number |
125 | Easy | Two pointers, String | Valid Palindrome |
234 | Easy | Linked List, Two Pointers | Palindrome Linked List |
ID | Difficulty | Tags | Solution |
---|---|---|---|
3 | Medium | Hash Table (Dictionary), Two pointer, Sub string, Sliding window | Longest Substring Without Repeating Characters |
438 | Easy | Hash Table (Dictionary), Two pointer, Sub string, Sliding window | Find All Anagrams in a String |
-- | Easy | Sliding window for sub string | SubString Template |
- Roman to Integer
Symbol | I | V | X | L | C | D | M Value | 1 | 5 | 10 | 50 | 100 | 500 | 1000
I placed before V or X indicates one less, so IV is 4 (5 - 1) and IX is 9 (10 - 9)
X placed before L or C indicates ten less, so XL is 40 (50 - 10) and XC is 90 (100 - 10)
C placed before D or M indicates a hundred less, so four hundred is CD (a hundred less than five hundred) and nine hundred is CM (a hundred less than a thousand)