problem

Longest Common Prefix

挨个比较每个字符串的元素是否相同,连续对应位置字符都相同,则为共同字符;否则不是。

code

class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
string prefix;
if(strs.size()==) return prefix;
for(int i=; i<strs[].size(); i++)
{
int j = ;
for( ; j<strs.size(); j++)
{
if(strs[j][i]==strs[][i]) continue;
else break;
}
if(j==strs.size()) prefix.push_back(strs[][i]);
else break; }
return prefix;
} //Vertical scanning.
};

参考

1.Leetcode-problem

【leetcode】14-LongestCommonPrefix的更多相关文章

  1. 【LeetCode】14. Longest Common Prefix 最长公共前缀

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:prefix, 公共前缀,题解,leetcode, 力扣 ...

  2. 【LeetCode】14. Longest Common Prefix 最长前缀子串

    题目: Write a function to find the longest common prefix string amongst an array of strings. 思路:求最长前缀子 ...

  3. 【LeetCode】14 - Longest Common Prefix

    Write a function to find the longest common prefix string amongst an array of strings. Solution: cla ...

  4. 【LeetCode】14. 最长公共前缀

    题目 编写一个函数来查找字符串数组中的最长公共前缀.如果不存在公共前缀,返回空字符串 "". 示例 1:输入: ["flower","flow&quo ...

  5. 【LeetCode】14. Longest Common Prefix (2 solutions)

    Longest Common Prefix Write a function to find the longest common prefix string amongst an array of ...

  6. 【LeetCode】数组--合并区间(56)

    写在前面   老粉丝可能知道现阶段的LeetCode刷题将按照某一个特定的专题进行,之前的[贪心算法]已经结束,虽然只有三个题却包含了简单,中等,困难这三个维度,今天介绍的是第二个专题[数组] 数组( ...

  7. 【LeetCode】873. Length of Longest Fibonacci Subsequence 解题报告(Python)

    [LeetCode]873. Length of Longest Fibonacci Subsequence 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: ...

  8. 【LeetCode】863. All Nodes Distance K in Binary Tree 解题报告(Python)

    [LeetCode]863. All Nodes Distance K in Binary Tree 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http ...

  9. 【LeetCode】813. Largest Sum of Averages 解题报告(Python)

    [LeetCode]813. Largest Sum of Averages 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...

  10. 【LeetCode】397. Integer Replacement 解题报告(Python)

    [LeetCode]397. Integer Replacement 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/inte ...

随机推荐

  1. py 正在爬取第%d页的美眉图

    #coding=utf-8import reimport requestsfrom bs4 import BeautifulSoupnums = 1num = 1while True: url = & ...

  2. stream.map示例

    引用1:https://blog.csdn.net/sanchan/article/details/70753645 引用2:https://www.ibm.com/developerworks/cn ...

  3. Ubuntu16.10下使用VSCode开发.netcore

    按照通常的套路,首先创建一个空白的解决方案,需要用到.netcore sdk命令: dotnet new sln -o dotnetcore_tutrorial 这个时候可以看到在目标目录下生成了一个 ...

  4. Win10系列:WinJS库控件

    在介绍了如何使用标准的HTML控件以及WinJS库中提供的新控件之后,下面来着重介绍WinJS库中几种常用的控件. (1)ListView控件 在开发Windows应用商店应用时可以使用ListVie ...

  5. spring bean 的生命周期

    感谢博友,内容源于博友的文章 http://www.cnblogs.com/zrtqsk/p/3735273.html 通过了解spring的bean 的生命周期 ,再结合jdk的注解,继承sprin ...

  6. export及export default

    const a=2; const b=3; const c=function(){console.log(a+b} export a; export b; export default c; 如上文件 ...

  7. LeetCode刷题 Flood Fill 洪水填充问题

    An  image is represented by a 2-D array of integers,each integers,each integer respresenting the sta ...

  8. 平面图转对偶图&19_03_21校内训练 [Everfeel]

    对于每个平面图,都有唯一一个对偶图与之对应.若G‘是平面图G的对偶图,则满足: G'中每一条边的两个节点对应着G中有公共边的面,包括最外部无限大的面. 直观地讲,红色标出来的图就是蓝色标出的图的对偶图 ...

  9. 一个canvas的demo

    该demo放于tomcat下运行,否则出现跨域错误 <!DOCTYPE html> <html> <head> <meta charset="utf ...

  10. 稀疏 部分 Checkout

    To easily select only the items you want for the checkout and force the resulting working copy to ke ...