Longest Common Prefix

来源:互联网 发布:linux子系统 编辑:程序博客网 时间:2024/06/09 23:02
Write a function to find the longest common prefix string amongst an array of strings.
class Solution:    # @return a string    def longestCommonPrefix(self, strs):        minLength = 99999        shortest = ''        for i in strs:            if len(i) < minLength : minLength = len(i); shortest = i        prefix = ''        for i in range(0,len(shortest)):            char = shortest[i]                        for j in range(0,len(strs)):                if strs[j][i] != char : return prefix            prefix += char        return prefix                                       

0 0
原创粉丝点击