class Solution:
def longestCommonPrefix(self, strs: List[str]) -> str:
if len(strs) == 0:
return ''
if len(strs) == 1:
return strs[0]
strs.sort()
prefix = ''
first, last = strs[0], strs[-1]
if len(first) == 0:
return prefix
for i in range(min(len(first), len(last))):
if first[i] == last[i]:
prefix += first[i]
else:
return prefix
return prefix