#14
Longest Common Prefix
pupil · 475 · lc easy +27 · verified · 47.2% accepted · 21,133 likes · top 32%
Description
Determine the longest string that is a leading prefix of every string in the input array. Return an empty string "" if no common prefix exists.
Example 1:
Input: strs = ["flower","flow","flight"]
Output: "fl"
Example 2:
Input: strs = ["dog","racecar","car"]
Output: ""
Explanation: There is no common prefix among the input strings.
Code
1
2
3