首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
最长公共前缀
[编程题]最长公共前缀
热度指数:176367
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 256M,其他语言512M
算法知识视频讲解
给你一个大小为 n 的字符串数组 strs ,其中包含n个字符串 , 编写一个函数来查找字符串数组中的最长公共前缀,返回这个公共前缀。
数据范围:
,
进阶:空间复杂度
,时间复杂度
示例1
输入
["abca","abc","abca","abc","abcc"]
输出
"abc"
示例2
输入
["abc"]
输出
"abc"
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
查看答案及解析
添加笔记
求解答(10)
邀请回答
收藏(742)
分享
提交结果有问题?
0个回答
251篇题解
添加回答
这道题你会答吗?花几分钟告诉大家答案吧!
提交观点
问题信息
字符串
难度:
0条回答
742收藏
24227浏览
热门推荐
通过挑战的用户
查看代码
求乞者
2022-10-31 17:02:28
牛客17999...
2022-09-16 17:56:23
12:00
2022-09-16 17:19:08
院中的柿子树
2022-09-16 16:29:16
不停20190...
2022-09-16 16:13:24
相关试题
某时刻系统资源总数(8,5,7),...
操作系统
评论
(1)
如下图所示的哈夫曼树,已知该哈夫曼...
树
评论
(1)
千亿模型训练中,数据并行(DP)通...
大模型开发
评论
(1)
以下关于MLCC的说法中,错误的是?
元器件
评论
(1)
循环队列在固定大小的数组实现中的核...
队列
评论
(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字符串vector * @return string字符串 */ string longestCommonPrefix(vector
& strs) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param strs string字符串一维数组 # @return string字符串 # class Solution: def longestCommonPrefix(self , strs ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param strs string字符串一维数组 * @return string字符串 */ public string longestCommonPrefix (List
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: List[str]) -> str: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param strs string字符串一维数组 * @return string字符串 */ func longestCommonPrefix( strs []string ) string { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param strs string字符串一维数组 * @param strsLen int strs数组长度 * @return string字符串 */ char* longestCommonPrefix(char** strs, int strsLen ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param strs string字符串一维数组 # @return string字符串 # class Solution def longestCommonPrefix(strs) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param strs string字符串一维数组 * @return string字符串 */ def longestCommonPrefix(strs: Array[String]): String = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param strs string字符串一维数组 * @return string字符串 */ fun longestCommonPrefix(strs: Array
): String { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param strs string字符串一维数组 * @return string字符串 */ public String longestCommonPrefix (String[] strs) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param strs string字符串一维数组 * @return string字符串 */ export function longestCommonPrefix(strs: string[]): string { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param strs string字符串一维数组 * @return string字符串 */ func longestCommonPrefix ( _ strs: [String]) -> String { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param strs string字符串一维数组 * @return string字符串 */ pub fn longestCommonPrefix(&self, strs: Vec
) -> String { // write code here } }
["abca","abc","abca","abc","abcc"]
"abc"
["abc"]
"abc"