diff --git a/014_Longest_Common_Prefix.py b/014_Longest_Common_Prefix.py new file mode 100644 index 0000000..adf7e16 --- /dev/null +++ b/014_Longest_Common_Prefix.py @@ -0,0 +1,9 @@ +class Solution: + def longestCommonPrefix(self, strs: List[str]) -> str: + common='' + strs[:]=sorted(strs) + first, last = strs[0], strs[-1] + for i in range(min(len(first),len(last))): + if first[i] != last[i]: return common + else: common+=first[i] + return common