首页
题库
面试
求职
学习
竞赛
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收藏
3814浏览
热门推荐
通过挑战的用户
牛客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
评论
(0)
如果你想列出当前目录以及子目录下所...
算法工程师
映客
2020
评论
(2)
以下代码的运行结果为():#inc...
算法工程师
映客
2020
评论
(2)
相邻的糖果
贪心
评论
(6)
【模板】二维费用背包
动态规划
小红书
评论
(2)
最长公共前缀
扫描二维码,关注牛客网
意见反馈
下载牛客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"