首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

[LeetCode] Longest Common Prefix 最长公共前缀 [LeetCode] Longest Common Prefix 最长公共前缀

链接:https://leetcode.com/problems/longest-common-prefix/#/description 难度:Easy 题目:14. Longest Common Prefix Write a function to find the longest common prefix string amongst an array of strings. 翻译:编写一个函数来查找给定字符串数组中最长的公共前缀。 思路:取出给定字符串数组中长度最小的一个字符串(或者直接取出第一个字符串),以此为基准,遍历整个字符串数组,若基准字符串是其他所有字符串的子串,则基准字符串即为所求最长公共前缀,否则,将基准字符串截去最后一个字符,重新遍历整个字符串数组,依此类推,直到找到所有字符串数组都存在的子串为止。 参考代码:

02
领券