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:
Comparing character by character: all strings share 'f' at index 0 and 'l' at index 1. At index 2, 'flower' and 'flow' have 'o' but 'flight' has 'i', so the prefix stops at '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.