标签:tco turn 超出 range function str 范围 long for
Write a function to find the longest common prefix(前缀) string amongst an array of strings.
1 class Solution(object): 2 def longestCommonPrefix(self, strs): 3 """ 4 :type strs: List[str] 5 :rtype: str 6 """ 7 if strs==[]: 8 return ‘‘ 9 10 res = ‘‘ 11 for j in xrange (0,len(strs[0])): 12 for i in xrange (1,len(strs)): 13 if j > len(strs[i])-1 or strs[0][j] != strs[i][j]: 14 return res 15 res = res+strs[0][j] 16 return res 17
注意strs[i][j]不要超出范围
标签:tco turn 超出 range function str 范围 long for
原文地址:http://www.cnblogs.com/fullest-life/p/6489089.html