14. Longest Common Prefix
Description
Write a function to find the longest common prefix string amongst an array of strings.
If there is no common prefix, return an empty string “”.
Example 1:1
2Input: ["flower","flow","flight"]
Output: "fl"
Code
1 | class Solution(object): |
Python
zip(*)
1 | arr = ["flower","flow","flight"] |
(‘f’, ‘f’, ‘f’)
(‘l’, ‘l’, ‘l’)
(‘o’, ‘o’, ‘i’)
(‘w’, ‘w’, ‘g’)
zip(*) unpack
min()
1 | print(min(arr)) |
flight