classSolution: deflongestCommonPrefix(self, strs) -> str: ifnot strs: return'' r = [] for item inzip(*strs): r.append(len(set(item)) == 1) r += [0] res = strs[0][:r.index(0)] return res
def__init__(self, arr): for item in ex: print(self.longestCommonPrefix(item))
ex = [["dog", "racecar", "car"], ["flower", "flow", "flight"], []] Solution(ex)