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

Solution:

 class Solution {
public:
string longestCommonPrefix(vector<string>& strs) { //runtime:4ms
string str="";
if(strs.empty())return str;
int index=; while(true){
if(index>=strs[].size())return str;
char c=strs[][index];
for(int i=;i<strs.size();i++){
if(index>=strs[i].size()||strs[i][index]!=c)return str;
}
str+=c;
index++;
} }
};

【LeetCode】14 - Longest Common Prefix的更多相关文章

  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 (2 solutions)

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

  4. 【一天一道LeetCode】#14 Longest Common Prefix

    一天一道LeetCode系列 (一)题目: Write a function to find the longest common prefix string amongst an array of ...

  5. 【LeetCode】014. Longest Common Prefix

    Write a function to find the longest common prefix string amongst an array of strings. 题解: 简单的暴力遍历解决 ...

  6. [LeetCode][Python]14: Longest Common Prefix

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest ...

  7. C# 写 LeetCode easy #14 Longest Common Prefix

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

  8. LeetCode题解(14)--Longest Common Prefix

    https://leetcode.com/problems/longest-common-prefix/ 原题: Write a function to find the longest common ...

  9. 《LeetBook》leetcode题解(14):Longest Common Prefix[E]

    我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...

随机推荐

  1. c# 计算1-100之间的所有整数的和

    求1-100所有整数和: class Program { static void Main(string[] args) { ,); Console.WriteLine("1-100之间所有 ...

  2. javascript ajax的语法

    ajax参数: 详细参数转到如下地址: http://www.w3school.com.cn/jquery/ajax_ajax.asp $.ajax语法: jQuery.ajax([settings] ...

  3. 关于RotateAnimation的各构造方法的参数

    本文以RotateAnimation的构造方法 讲解. RotateAnimation(float fromDegrees, float toDegrees) 其他构造器的旋转也可参考这副图. Rot ...

  4. Getting Started Synchronizing Files

    https://msdn.microsoft.com/en-US/library/bb902813(v=sql.110).aspx Sync Framework includes a file syn ...

  5. leetcode:Search a 2D Matrix(数组,二分查找)

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  6. Java生成可执行文件 & MANIFEST.MF问题 METAINFO

    用 Intellij 进行打包.在File -> Project Structure里面. 然后应该会自动生成Jar包(也可以Build->Build Artifacts) xxx.jar ...

  7. Asp.Net验证码1

    验证码html调用 验证码:<input name="> <img src="CodeHandler.ashx" id="imgCode&qu ...

  8. spring tx:advice 和 aop:config 配置事务

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  9. myeclipes准备工作

    设置jsp中默认编码为utf-8

  10. UVALive 4043 Ants 蚂蚁(二分图最佳完美匹配,KM算法)

    题意: 有n个蚂蚁n棵树,蚂蚁与树要配对,在配对成功的一对之间连一条线段,要求所有线段不能相交.按顺序输出蚂蚁所匹配的树. 思路: 这个题目真是技巧啊,不能用贪心来为每个蚂蚁选择最近的树,这样很可能是 ...