题目描述
编写一个函数来查找字符串数组中的最长公共前缀。
示例1
输入
["abca","abc","abca","abc","abcc"]
返回值
"abc"
# # # @param strs string字符串一维数组 # @return string字符串 # class Solution: def longestCommonPrefix(self , strs ): # write code here if len(strs)==0: return "" elif len(strs)==1: return strs[0] else: re = "" for i in range(len(strs[0])): for j in strs[1:]: if len(j)==i or strs[0][i]!=j[i]: return re re = re+strs[0][i] return re