Fork me on GitHub

longest_common_prefix

longest_common_prefix

Posted by Kaelzhang on July 30, 2015

#####需求描述:

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

写一个函数获取字符串数组中最长的字符串前缀


#####pythonic实现:

class Solution:
    def longestCommonPrefix(self, strs):
        ret, l = '', len(strs)
        for t in zip(*strs):
            if t != tuple(t[0] * l):
                break
            ret += t[0]
        return ret

  • 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!