Python:using sort,beats 98.76%


  • 0
    Q

    class Solution(object):
    def longestCommonPrefix(self, strs):
    """
    :type strs: List[str]
    :rtype: str
    """
    if not strs:
    return ''
    strs.sort()
    ret = ''
    for k, v in enumerate(strs[0]):
    if v == strs[len(strs)-1][k]:
    ret += v
    else:
    break
    return ret


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.