Description

Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "".

Examples

Input:strs = ["flower","flow","flight"]
Output:"fl"
Explanation:

The longest common prefix is 'fl'.

Input:strs = ["dog","racecar","car"]
Output:""
Explanation:

There is no common prefix among the input strings.

Input:strs = ["programming","program","progress","project"]
Output:"pro"
Explanation:

All strings start with 'pro', but differ at the fourth character: 'programming' and 'program' have 'g', while 'progress' has 'g' and 'project' has 'j'. The longest common prefix is 'pro'.

Constraints

  • 1 ≤ strs.length ≤ 200
  • 0 ≤ strs[i].length ≤ 200
  • strs[i] consists of only lowercase English letters.

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!