题解 | #最长公共前缀#

最长公共前缀

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
全部评论

相关推荐

后端转测开第一人:再怎么劝退也没用的 某些群体总以为在一个幸存者偏差的软件上看见了极少数秋招上岸某个大厂的个例就幻想上了 事实上自己打开ssob沟通1000+连个小厂面试都没
点赞 评论 收藏
分享
09-22 15:45
门头沟学院 Java
谁给娃offer我给...:我也遇到了,我说只要我通过面试我就去,实际上我根本就不会去😁
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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