Dashboard
LC #14
Longest Common Prefix
Pattern · ?
Problem
Write a function to find the longest common prefix string amongst an array of strings.
Constraints
- 1 ≤ strs.length ≤ 200
- 0 ≤ strs[i].length ≤ 200
- strs[i] consists of only lower-case English letters.
Example
- Input
- strs = ["flower", "flow", "flight"]
- Output
- "fl"
- Why
- "fl" is the longest string that is a prefix of all inputs.
Spot the pattern
Which pattern cracks it?
Hints
One at a time