惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
Stack Overflow Blog
Stack Overflow Blog
G
Google Developers Blog
Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
L
LangChain Blog
T
The Blog of Author Tim Ferriss
J
Java Code Geeks
Y
Y Combinator Blog
月光博客
月光博客
雷峰网
雷峰网
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
F
Fortinet All Blogs
A
About on SuperTechFans
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
小众软件
小众软件
H
Help Net Security
Last Week in AI
Last Week in AI
B
Blog RSS Feed
宝玉的分享
宝玉的分享
N
Netflix TechBlog - Medium
博客园 - 叶小钗
The GitHub Blog
The GitHub Blog

Lan小站-嗯,不错! - 算法刷题

17. 电话号码的字母组合 - Lan小站-嗯,不错! 77. 组合 - Lan小站-嗯,不错! 283. 移动零 - Lan小站-嗯,不错! 189. 轮转数组 - Lan小站-嗯,不错! 13. 罗马数字转整数 - Lan小站-嗯,不错! 28. 找出字符串中第一个匹配项的下标 双指针 - Lan小站-嗯,不错! 【Hot100】【一般】3. 无重复字符的最长子串 - Lan小站-嗯,不错! 【周赛】【简单】6362. 合并两个二维数组 - 求和法 - Lan小站-嗯,不错! 【简单】144. 二叉树的前序遍历 - Lan小站-嗯,不错!
14. 最长公共前缀 - Lan小站-嗯,不错!
Lan · 2023-09-15 · via Lan小站-嗯,不错! - 算法刷题

Lan

2023-09-15 / 0 评论 / 324 阅读 / 正在检测是否收录...

本文最后更新于2023年09月15日,已超过1003天没有更新,若内容或图片失效,请留言反馈。

编写一个函数来查找字符串数组中的最长公共前缀。

如果不存在公共前缀,返回空字符串 ""。

示例 1:

输入:strs = ["flower","flow","flight"]
输出:"fl"
示例 2:

输入:strs = ["dog","racecar","car"]
输出:""
解释:输入不存在公共前缀。

提示:

1 <= strs.length <= 200
0 <= strs[i].length <= 200
strs[i] 仅由小写英文字母组成

class Solution:
    def longestCommonPrefix(self, strs: List[str]) -> str:
        index, res, min_len = 0, "", min([len(s) for s in strs]),
        for i in range(min_len):
            temp = ''
            for j in strs:
                if temp == '':
                    temp = j[i]
                elif j[i] != temp:
                    return res
            res += temp
        return res

1694707569773.webp

评论