Write a function to find the longest common prefix string amongst an array of strings.

解题思路:

class Solution:
    # @return a string
    def longestCommonPrefix(self, strs):
        if strs == []:
            return ''

        minl = 99999
        for i in strs:
            if len(i) < minl:
                minl = len(i)

        pre = ''
        for i in range(minl):
            t = strs[0][i]
            for j in range(1,len(strs)):
                if t != strs[j][i]:
                    return pre
            pre += t
        return pre

相关文章:

  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2021-12-24
猜你喜欢
  • 2022-01-18
  • 2021-08-02
  • 2022-02-24
  • 2021-08-26
  • 2022-03-07
  • 2021-09-18
相关资源
相似解决方案