Skip to content

LC 0014 [E] Longest Common Prefix

Code with Senpai edited this page Dec 16, 2020 · 1 revision
class Solution:
    def longestCommonPrefix(self, strs):
        """
        :type strs: List[str]
        :rtype: str
        """
        if not strs:
            return ""
        shortest = min(strs,key=len)
        for i, ch in enumerate(shortest):
            for other in strs:
                if other[i] != ch:
                    return shortest[:i]
        return shortest 
Clone this wiki locally