Longest Common Prefix
EasyP2Coding
Return the longest string that is a prefix of every string in strs. If there is no common prefix, return the empty string.
Example 1
- Input
- strs = ["flower","flow","flight"]
- Output
- "fl"
Example 2
- Input
- strs = ["dog","racecar","car"]
- Output
- ""
Example 3
- Input
- strs = ["a"]
- Output
- "a"
Constraints
- 1 <= strs.length <= 200
- 0 <= strs[i].length <= 200
- strs[i] consists of lowercase letters.
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 11. ⌘Enter runs, ⌘⇧Enter submits.