Longest Common Prefix
EasyStrings
Given an array of words, return the longest string that every word starts with. If they share no start, return the empty string "".
Constraints
- 1 ≤ number of words ≤ 200
- 0 ≤ length of each word ≤ 200
- Words have lower-case English letters only.
Example 1
Input
words = ["flower","flow","flight"]
Output
"fl"
Why:
All three start with fl; flo fails for flight.
Example 2
Input
words = ["dog","racecar","car"]
Output
""
Why:
The first letters already differ.
Hints
Was this a good challenge?
- Solved by
- 0
- Submissions
- 0
- Accepted
- –