[LeetCode] Longest Common Prefix 파이썬 (zip, list comprehension, set)
class Solution: def longestCommonPrefix(self, strs: List[str]) -> str: strs = [list(x) for x in strs] strs = zip(*strs) pre = "" for a in strs: if len(set(a)) == 1: pre += a[0] else: break return pre # output # [['f', 'l', 'o', 'w', 'e', 'r'], ['f', 'l', 'o', 'w'], ['f', 'l', 'i', 'g', 'h', 't']] # ('f', 'f', 'f') # a output # {'f'} # set(a) # 1 # len(set(a)) # ('l', 'l', 'l') # {'l'} # 1 # ('o'..
2021. 3. 28.