Guest User

Untitled

a guest
Oct 16th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. class Solution:
  2. def longestCommonPrefix(self, strs):
  3. """
  4. :type strs: List[str]
  5. :rtype: str
  6. """
  7. if not strs: return ""
  8. strs = sorted(strs, key = len)
  9. i = 1
  10. pre = strs[0]
  11. while i < len(strs):
  12. if not pre in strs[i] or not strs[i].index(pre) == 0:
  13. pre = pre[:-1]
  14. i = 1
  15. else: i += 1
  16. return pre
Add Comment
Please, Sign In to add comment