HTMLify
LeetCode - Longest Common Prefix - Python
Views: 332 | Author: abh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | class Solution: def longestCommonPrefix(self, strs: List[str]) -> str: p = "" i = 0 while True: b = False cs = set() for s in strs: if i >= len(s): b = True else: cs.add(s[i]) if b: break if len(cs) > 1: break p += s[i] i += 1 return p |