class Solution: def longestCommonPrefix(self , strs: List[str]) -> str: # write code here if not strs: return '' if len(strs) == 1: return strs[0] res = [i for i in strs[0]] idx = 0 for i in range(1, len(strs)): word = strs[i] while idx < len(res): if idx > len(word)-1: res = res[:idx] break elif res[idx] != word[idx]: res = res[:idx] break elif res[idx] == word[idx]: idx += 1 idx = 0 return ''.join(res)