Skip to content

Commit

Permalink
Create longest-common-pref.py
Browse files Browse the repository at this point in the history
neat enough solution for longest common prefix
  • Loading branch information
gabedonnan authored Jan 14, 2023
1 parent 06bb242 commit b0bcc23
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions longest-common-pref.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution:
def longestCommonPrefix(self, strs: List[str]) -> str:
pref = strs[0]
for s in strs:
if pref == "":
return pref
for i in range(min(len(s),len(pref))):
if s[i] != pref[i]:
pref = pref[:i]
break
if len(pref) > len(s):
pref = pref[:len(s)]
return pref

0 comments on commit b0bcc23

Please sign in to comment.