首页 > 试题广场 >

最长公共前缀

[编程题]最长公共前缀
  • 热度指数:315 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
编写一个函数来查找字符串数组中的最长公共前缀。如果不存在公共前缀,返回空字符串 ""。
示例1

输入

["hello","hi","hey"]

输出

"h"
头像 giantye
发表于 2022-06-20 09:44:32
class Solution: def longestCommonPrefix(self , strs ): res = '' for items in zip(*strs): if len(set(items)) == 展开全文