首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
最长公共前缀
[编程题]最长公共前缀
热度指数:315
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 256M,其他语言512M
算法知识视频讲解
编写一个函数来查找字符串数组中的最长公共前缀。如果不存在公共前缀,返回空字符串 ""。
示例1
输入
["hello","hi","hey"]
输出
"h"
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
添加笔记
求解答(3)
邀请回答
收藏(7)
分享
纠错
提交结果有问题?
4个回答
1篇题解
开通博客
giantye
发表于 2022-06-20 09:44:32
class Solution: def longestCommonPrefix(self , strs ): res = '' for items in zip(*strs): if len(set(items)) ==
展开全文
问题信息
C++工程师
2020
映客
Java工程师
上传者:
小小
难度:
4条回答
7收藏
3708浏览
热门推荐
通过挑战的用户
牛客94086...
2023-02-23 23:30:00
牛客49521...
2023-01-17 11:02:31
牛客28756...
2022-11-08 12:05:43
主动的芝士在努力存钱
2022-11-07 16:09:43
顾顾啊
2022-10-28 19:24:15
相关试题
看图回答
判断推理
2020
人力资源
安永
审计
税务服务
风险管理
管理咨询
行政管理
评论
(1)
来自
职能类模拟题2
假定所有变量均已正确定义,则下列程...
算法工程师
映客
2020
评论
(0)
如果你想列出当前目录以及子目录下所...
算法工程师
映客
2020
评论
(2)
为下列代码设计测试用例,要求满足条...
软件测试
评论
(1)
定义如下Python函数用于记录操...
Python
评论
(1)
最长公共前缀
扫描二维码,关注牛客网
意见反馈
下载牛客APP,随时随地刷题
import java.util.*; public class Solution { /** * * @param strs string字符串一维数组 * @return string字符串 */ public String longestCommonPrefix (String[] strs) { // write code here } }
class Solution { public: /** * * @param strs string字符串一维数组 * @param strsLen int strs数组长度 * @return string字符串 */ string longestCommonPrefix(string* strs, int strsLen) { // write code here } };
# # # @param strs string字符串一维数组 # @return string字符串 # class Solution: def longestCommonPrefix(self , strs ): # write code here
/** * * @param strs string字符串一维数组 * @return string字符串 */ function longestCommonPrefix( strs ) { // write code here } module.exports = { longestCommonPrefix : longestCommonPrefix };
# # # @param strs string字符串一维数组 # @return string字符串 # class Solution: def longestCommonPrefix(self , strs ): # write code here
["hello","hi","hey"]
"h"