Skip to content

Commit f86f6e7

Browse files
Create 014_Longest_Common_Prefix.py
1 parent 1cf03bf commit f86f6e7

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

014_Longest_Common_Prefix.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def longestCommonPrefix(self, strs: List[str]) -> str:
3+
common=''
4+
strs[:]=sorted(strs)
5+
first, last = strs[0], strs[-1]
6+
for i in range(min(len(first),len(last))):
7+
if first[i] != last[i]: return common
8+
else: common+=first[i]
9+
return common

0 commit comments

Comments
 (0)