String
LeetCode 504: Base 7
·1 min
LeetCode
Easy
Math
String
LeetCode 504 note: repeatedly take % 7 and // 7 of the absolute value, then add the sign and reverse; handle 0 separately
LeetCode 500: Keyboard Row
·1 min
LeetCode
Easy
Array
Hash-Table
String
LeetCode 500 note: make a set for each keyboard row and keep words whose lowercase character set is a subset of one row
LeetCode 482: License Key Formatting
·2 mins
LeetCode
Easy
String
LeetCode 482 note: remove every dash and uppercase first, then cut groups of k from the end so only the first group may be shorter
LeetCode 459: Repeated Substring Pattern
·1 min
LeetCode
Easy
String
String-Matching
Z-Algorithm
Knuth-Morris-Pratt-Algorithm
LeetCode 459 note: s is a repetition of a substring exactly when s occurs in s + s with its first and last characters removed
LeetCode 434: Number of Segments in a String
·1 min
LeetCode
Easy
String
LeetCode 434 note: split() with no argument ignores extra spaces, so the number of pieces is the answer
LeetCode 415: Add Strings
·2 mins
LeetCode
Easy
Math
String
Simulation
LeetCode 415 note: add digit by digit from the ends with two pointers, tracking the carry, and append any leftover carry after the loop
LeetCode 1869: Longer Contiguous Segments of Ones than Zeros
·1 min
LeetCode
Easy
String
LeetCode 1869 note: find the longest run of 1s and of 0s and compare; split does it in one line
LeetCode 1446: Consecutive Characters
·1 min
LeetCode
Easy
String
LeetCode 1446 note: track the current run of equal characters in one pass, resetting to 1 on a change
LeetCode 412: Fizz Buzz
·1 min
LeetCode
Easy
Math
String
Simulation
LeetCode 412 note: check multiples of 15 first, then 5 and 3; multiples need %, not //
LeetCode 409: Longest Palindrome
·2 mins
LeetCode
Easy
Hash-Table
String
Greedy
LeetCode 409 note: use an even number of each character on the two sides, plus one in the middle if any count is odd
LeetCode 405: Convert a Number to Hexadecimal
·2 mins
LeetCode
Easy
Math
String
Bit-Manipulation
LeetCode 405 note: add 2^32 to a negative number to get its two’s complement, then take 4 bits at a time (% 16); handle 0 separately
LeetCode 392: Is Subsequence
·2 mins
LeetCode
Easy
Two-Pointers
String
Dynamic-Programming
LeetCode 392 note: two pointers; the pointer on t always advances, and the one on s advances on a match; bound-check both