Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info

Input: ["flower", "flow", "flight" ] → Output: "fl"

Input: ["dog", "racecar", "car"] → Output: ""


Code Block
languagepy
class Solution:
    def longestCommonPrefix(self, strs: List[str]) -> str:
        if not strs:
            return ""
        
        result=""
        cnt=len(strs)
        for i in range(len(strs[0])):
            j=1
            while j<cnt and i<len(strs[j]) and strs[j][i]==strs[0][i]: j+=1
                
            if j==cnt:
                result += strs[0][i]
            else:
                break;
        
        return result;

...