Algorithms · Ongoing practice
LeetCode Python
Clean, readable Python solutions to classic array and string problems, tracked on GitHub.
Stack
- Python
Solutions
A personal practice log rather than a product. Each file is a self-contained Solution class with a quick example run at the bottom. Several solutions use single passes and in-place updates. Others, like Two Sum, are the straightforward first version.
| Problem | Approach |
|---|---|
| Two Sum | Check every pair (brute force) |
| Best Time to Buy and Sell Stock | One pass, tracking the minimum price so far |
| Merge Sorted Array | Two-pointer merge |
| Plus One | Carry propagation from the last digit |
| Remove Duplicates from Sorted Array | Slow/fast pointers, in place |
| Remove Element | Slow/fast pointers, in place |
| Search Insert Position | Linear scan for the first value ≥ target |
| Length of Last Word | Reverse scan, skipping trailing spaces |
| Longest Common Prefix | Vertical character-by-character scan |
| Valid Anagram | Length check, then per-character counts |
Plus One.pySource (opens GitHub in a new tab)
class Solution: def plusOne(self, digits: list[int]) -> list[int]: for i in range(len(digits) - 1, -1, -1): if digits[i] < 9: digits[i] += 1 return digits digits[i] = 0 return [1] + digits