牛客题霸-算法篇
最长公共前缀
相似的企业真题
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 64M,其他语言128M
热度指数:15958
本题知识点:
字符串
算法知识视频讲解
校招时部分企业笔试将禁止编程题跳出页面,为提前适应,练习时请使用在线自测,而非本地IDE。
题目描述
编写一个函数来查找字符串数组中的最长公共前缀。
示例1
输入
复制
["abca","abc","abca","abc","abcc"]
["abca","abc","abca","abc","abcc"]
返回值
复制
"abc"
"abc"
上一题
下一题
登录
/
注册
我的提交
编辑器加载中...
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 } };
# # # @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
package main /** * * @param strs string字符串一维数组 * @return string字符串 */ func longestCommonPrefix( strs []string ) string { // 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"