LeetCode
LeetCode 257: Binary Tree Paths
·1 min
LeetCode
Easy
String
Backtracking
Tree
Depth-First-Search
LeetCode 257 note: DFS carrying the path string down, adding the whole path at each leaf
LeetCode 242: Valid Anagram
·2 mins
LeetCode
Easy
Hash-Table
String
Sorting
LeetCode 242 note: two strings are anagrams exactly when their character counts match; compare Counters or sorted strings
LeetCode 237: Delete Node in a Linked List
·1 min
LeetCode
Medium
Linked-List
LeetCode 237 note: without the previous node, copy the next node’s value over and delete the next node instead
LeetCode 235: Lowest Common Ancestor of a Binary Search Tree
·2 mins
LeetCode
Medium
Tree
Depth-First-Search
Binary-Search-Tree
Binary-Tree
LeetCode 235 note: go left when both p and q are smaller, right when both are larger; otherwise (split, or one is the node itself) this node is the LCA
LeetCode 234: Palindrome Linked List
·2 mins
LeetCode
Easy
Linked-List
Two-Pointers
Stack
Recursion
LeetCode 234 note: find the middle with fast and slow pointers, reverse the second half, and compare from both ends with O(1) extra space
LeetCode 232: Implement Queue using Stacks
·1 min
LeetCode
Easy
Stack
Design
Queue
LeetCode 232 note: two stacks, where in receives pushes and out is refilled from in only when empty, amortized O(1)
LeetCode 231: Power of Two
·2 mins
LeetCode
Easy
Math
Bit-Manipulation
Recursion
LeetCode 231 note: a power of two has exactly one set bit, and n & (n - 1) clears the lowest one, so the result is 0 exactly then; n must be positive
LeetCode 228: Summary Ranges
·2 mins
LeetCode
Easy
Array
LeetCode 228 note: scan once, extending the current range when a number continues the previous one and opening a new range otherwise, then format
LeetCode 226: Invert Binary Tree
·1 min
LeetCode
Easy
Tree
Depth-First-Search
Breadth-First-Search
Binary-Tree
LeetCode 226 note: swap every node’s children, using a simultaneous assignment so the already-changed side is not reused
LeetCode 225: Implement Stack using Queues
·2 mins
LeetCode
Easy
Stack
Design
Queue
LeetCode 225 note: one queue suffices: after a push, rotate all earlier elements to the back so the new element sits at the front
LeetCode 219: Contains Duplicate II
·2 mins
LeetCode
Easy
Array
Hash-Table
Sliding-Window
LeetCode 219 note: a hash map stores each value’s last index; only the most recent occurrence needs a distance check
LeetCode 217: Contains Duplicate
·1 min
LeetCode
Easy
Array
Hash-Table
Sorting
LeetCode 217 note: if converting to a set shortens the array, there is a duplicate