Created
March 13, 2016 09:44
-
-
Save yehjames/ad56c5b9d8c9aee909ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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