Longest Common Prefix

Easy

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 "".

Example 1

longestCommonPrefix()
Input
strs = ["flower","flow","flight"]
Output
"fl"

Example 2

longestCommonPrefix()
Input
strs = ["dog","racecar","car"]
Output
""

Why

There is no common prefix among the input strings.
Constraints
1 <= strs.length <= 200
0 <= strs[i].length <= 200

Topics

Strings

Implement longestCommonPrefix in the editor and return the answer — printing it is never graded.