题解 | #最长公共前缀#

最长公共前缀

http://www.nowcoder.com/practice/28eb3175488f4434a4a6207f6f484f47

#
# 
# @param strs string字符串一维数组 
# @return string字符串
#
class Solution:
    def longestCommonPrefix(self , strs ):
        # write code here
        length = len(strs)
        if strs == '' or (length == 0):
            return ""
        pre = strs[0]
        i = 1
        while (i < len(strs)):
            while(strs[i].find(pre) == -1):
                pre = pre[0:len(pre)-1]
            i=i+1
        return pre
全部评论

相关推荐

点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务