SHARE
TWEET

Untitled

a guest Feb 27th, 2020 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution:
  2.     def longestCommonPrefix(self, strs: List[str]) -> str:
  3.         prefix = ""
  4.         if strs and len(strs) > 1:
  5.             sorted_list = sorted(strs)
  6.             first = sorted_list[0]
  7.             last = sorted_list[-1]
  8.             for i in range(len(first)):
  9.                 if len(last) > i and last[i] == first[i]:
  10.                     prefix += last[i]
  11.                 else:
  12.                     return prefix
  13.         elif len(strs) == 1:
  14.             return strs[0]
  15.         else:
  16.             return ""
  17.         return prefix
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top