Skip to content

Instantly share code, notes, and snippets.

@yehjames
Created March 13, 2016 09:44
Show Gist options
  • Save yehjames/ad56c5b9d8c9aee909ea to your computer and use it in GitHub Desktop.
Save yehjames/ad56c5b9d8c9aee909ea to your computer and use it in GitHub Desktop.
class Solution:
def lcp(self, str1, str2):
i = 0
while (i < len(str1) and i < len(str2)):
if str1[i] == str2[i]:
i = i+1
else:
break
return str1[:i]
# @return a string
def longestCommonPrefix(self, strs):
if not strs:
return ''
else:
return reduce(self.lcp,strs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment