Leetcode:14.最长公共前缀
2020-01-12 13:32
375 查看
[code]def longestCommonPrefix(strs): result = "" for tmp in zip(*strs): print(tmp) # 对所有的相同位置的元素进行去重,如果长度是1则代表全是一样的 if len(set(tmp)) == 1: #用set很灵性 result += tmp[0] else: break print(result) strs=["flower","flow","flight"] print(*strs) longestCommonPrefix(strs)
输出:
flower flow flight
('f', 'f', 'f') #<class 'tuple'>
('l', 'l', 'l')
('o', 'o', 'i')
fl
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- LeetCode 14.最长公共前缀--Python3
- Leetcode-14.最长公共前缀
- LeetCode14:最长公共前缀
- LeetCode14. 最长公共前缀
- [算法Rust,Go,Python,JS实现)]LeetCode之14-最长公共前缀
- leetcode 14 最长公共前缀(python)
- LeetCode——14 最长公共前缀
- leetcode-14-最长公共前缀
- LeetCode 14 Longest Common Prefix(最长公共前缀)(String)
- 【LeetCode】[14] 最长公共前缀
- 力扣(LeetCode 14)最长公共前缀 python
- LeetCode 14 最长公共前缀(字符串)
- Leetcode 14: 最长公共前缀(Longest Common Prefix)
- leetcode-腾讯精选练习(50 题)python #14最长公共前缀
- 【LeetCode】14. 最长公共前缀
- leetcode的python实现 刷题笔记14:最长公共前缀
- LeetCode 14. 最长公共前缀
- LeetCode 14 Longest Common Prefix(最长公共前缀)
- 【leetcode每日一题】【2019-05-20】14. 最长公共前缀
- leetcode14. 最长公共前缀