↓Skip to main content

String

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 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 884: Uncommon Words from Two Sentences
·1 min
LeetCode Easy Hash-Table String Counting
LeetCode 884 note: count words across both sentences together; those appearing exactly once are the answer
LeetCode 859: Buddy Strings
·2 mins
LeetCode Easy Hash-Table String
LeetCode 859 note: lengths must match; identical strings need a repeated character; otherwise exactly two positions differ and cross-match
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 824: Goat Latin
·1 min
LeetCode Easy String
LeetCode 824 note: split into words and convert each: move a leading consonant to the end, then append ma and i + 1 copies of a
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 819: Most Common Word
·2 mins
LeetCode Easy Array Hash-Table String Counting
LeetCode 819 note: replace punctuation with spaces, lowercase, split, count, and pick the most frequent word not banned
LeetCode 806: Number of Lines To Write String
·2 mins
LeetCode Easy Array String
LeetCode 806 note: simulate writing, wrapping when the next letter would exceed 100; landing exactly on 100 stays on the line
LeetCode 804: Unique Morse Code Words
·1 min
LeetCode Easy Array Hash-Table String
LeetCode 804 note: translate each word into a Morse string and count the distinct results with a set
LeetCode 796: Rotate String
·2 mins
LeetCode Easy String String-Matching
LeetCode 796 note: goal is a rotation of s exactly when the lengths match and goal occurs in s + s
LeetCode 771: Jewels and Stones
·1 min
LeetCode Easy Hash-Table String
LeetCode 771 note: put jewels in a set and count how many stones are in it