Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- """
- @param strs: A list of strings
- @return: The longest common prefix
- """
- def longestCommonPrefix(self, strs):
- # write your code here
- if len(strs)==0:
- return ""
- for prefix in range(len(strs[0])):
- mark = strs[0][prefix]
- for word in strs[1:]:
- if prefix < len(word):
- if word[prefix] != mark:
- return strs[0][:prefix]
- else:
- return strs[0][:prefix]
- return strs[0]
Add Comment
Please, Sign In to add comment