問題
Write a function to find the longest common prefix string amongst an array of strings.
分析:
最長前綴
Python
class Solution:
def longestCommonPrefix(self, strs):
"""
:type strs: List[str]
:rtype: str
"""
ans = ""
i = 0
while strs:
if len(strs[0]) > i:
currc = strs[0][i]
else: break
for s in strs:
if len(s) <= i or s[i] != currc:
return ans
ans += currc
i += 1
return ans