Skip to content
CodeShare
All problems

Longest Common Prefix

Find the longest start that every word shares.

EasyStrings

Given an array of strings strs, return the longest string that is a prefix of every one of them. If they don't share a prefix, return an empty string.

Examples

Example 1
Input
strs = ["flower", "flow", "flight"]
Output
"fl"
Example 2
Input
strs = ["dog", "racecar", "car"]
Output
""
Why
The words don't share a first letter.

Constraints

  • 1 <= strs.length <= 200
  • 0 <= strs[i].length <= 200
  • Strings contain only lowercase English letters.