Solution

  1. def longestCommonPrefix(self, strs):
  2. if not strs:
  3. return ""
  4. shortest = min(strs, key=len)
  5. for i, ch in enumerate(shortest):
  6. for other in strs:
  7. if other[i] != ch:
  8. return shortest[:i]
  9. return shortest

Python enumerate()函数