题解 | #最长公共前缀#
最长公共前缀
http://www.nowcoder.com/practice/28eb3175488f4434a4a6207f6f484f47
#
#
# @param strs string字符串一维数组
# @return string字符串
#
class Solution:
def longestCommonPrefix(self , strs ):
# write code here
if len(strs) < 1:
return ''
if len(strs) == 1:
return strs[0]
m = min(map(len, strs))
for i in range(m):
if all([strs[j][i] == strs[0][i] for j in range(len(strs))]):
continue
else:
return strs[0][:i]
return strs[0][:m]
查看22道真题和解析

