Two-Pointers
LeetCode 925: Long Pressed Name
·2 mins
LeetCode
Easy
Two-Pointers
String
LeetCode 925 note: one pointer each over name and typed; every typed character either matches the next name character or repeats the previous typed character
LeetCode 922: Sort Array By Parity II
·1 min
LeetCode
Easy
Array
Two-Pointers
Sorting
LeetCode 922 note: pointers i over even slots and j over odd slots, each stepping by two; when slot i holds an odd number, move j to a misplaced even and swap
LeetCode 917: Reverse Only Letters
·2 mins
LeetCode
Easy
Two-Pointers
String
LeetCode 917 note: two pointers each skip non-letters and swap when both point at letters; convert the string to a list first
LeetCode 905: Sort Array By Parity
·1 min
LeetCode
Easy
Array
Two-Pointers
Sorting
LeetCode 905 note: a write pointer swaps even numbers to the front, just like move zeroes
LeetCode 876: Middle of the Linked List
·2 mins
LeetCode
Easy
Linked-List
Two-Pointers
LeetCode 876 note: fast moves two steps and slow one; when fast reaches the end slow is in the middle, the right-middle for even lengths
LeetCode 844: Backspace String Compare
·2 mins
LeetCode
Easy
Two-Pointers
String
Stack
Simulation
LeetCode 844 note: simulate backspaces with a stack; for O(1) space, walk from the end and count how many characters each # skips
LeetCode 832: Flipping an Image
·2 mins
LeetCode
Easy
Array
Two-Pointers
Bit-Manipulation
Matrix
LeetCode 832 note: reverse each row and invert its bits, which two pointers can do at once
LeetCode 821: Shortest Distance to a Character
·2 mins
LeetCode
Easy
Array
Two-Pointers
String
LeetCode 821 note: one left-to-right pass for the distance to the nearest c on the left, then a right-to-left pass taking the minimum
LeetCode 696: Count Binary Substrings
·2 mins
LeetCode
Easy
Two-Pointers
String
LeetCode 696 note: split the string into runs of equal characters; each adjacent pair of runs contributes min(previous, current) substrings
LeetCode 680: Valid Palindrome II
·2 mins
LeetCode
Easy
Two-Pointers
String
Greedy
LeetCode 680 note: at the first mismatch the only options are deleting the left or the right character; check whether either remainder is a palindrome
LeetCode 653: Two Sum IV - Input is a BST
·2 mins
LeetCode
Easy
Hash-Table
Two-Pointers
Tree
Depth-First-Search
LeetCode 653 note: traverse while keeping a set of seen values; finding k - val in it means a pair exists
LeetCode 557: Reverse Words in a String III
·1 min
LeetCode
Easy
Two-Pointers
String
LeetCode 557 note: split on spaces, reverse each word, and join with spaces