Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def longestCommonPrefix(self, strs):
- """
- :type strs: List[str]
- :rtype: str
- """
- if not strs: return ""
- strs = sorted(strs, key = len)
- i = 1
- pre = strs[0]
- while i < len(strs):
- if not pre in strs[i] or not strs[i].index(pre) == 0:
- pre = pre[:-1]
- i = 1
- else: i += 1
- return pre
Add Comment
Please, Sign In to add comment