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. ado执行sql查询出现“发送数据流时出现算术溢出”错误

    开发一个数据采集监控系统,比较变态的是有将近2000项数据.根据数据类型分多个表存储.数据库访问层采用ado.最近发现当一条sql一次性查询1700多个字段数据后就出现“发送数据流时出现算术溢出”错误 ...

  2. POJ 1904 HDU 4685

    这两道题差不多,POJ这道我很久以前就做过,但是比赛的时候居然没想起来.. POJ 这道题的题意是,N个王子每个人都有喜欢的公主,当他们选定一个公主结婚时,必须是的剩下的人也能找到他喜欢的公主结婚. ...

  3. ubuntu添加环境变量【原创】

    cpro放到环境变量里,并且加上可执行权限如果在本地添加,则需mkdir ~/bin mv cpro /home/zhangbh/bin/vi ~/.bashrcexport PATH=/usr/lo ...

  4. .Net MVC视图

    1.View显示 return View(): 默认为/Views/<控制器>/<方法> return View("Test"); 显示/View/< ...

  5. Ubuntu 14.10下安装深度音乐客户端

    很多刚从windows系统投靠到ubuntu的机油,在听音乐时不是很舒心.毕竟ubuntu软件中心的很多影音软件都是国外的朋友编写的,所以很多时候国内的朋友用着很不舒服.今天给大家推荐的是国内开发者针 ...

  6. 路由器扫描的Java源码

    这个源码不是本人写的,是我原来的领导写的,我们都叫他东哥,这个是东留给我的一个小资源,好佩服他哦,这个东西可以用来扫描全世界的路由器,破解路由器账户和密码 当然是简单的了.我能力不够没有更完善的补充下 ...

  7. HTML 空格的表示符号 nbsp / ensp / emsp 的区别?

      半角的不断行的空白格(推荐使用)   半角的空格   全角的空格   半角的不断行的空白格(推荐使用)    半角的空格     全角的空格

  8. [HDOJ2639]Bone Collector II(第k优01背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2639 题意:求01背包的第k优解 dp(i, j)表示容量为j时的i优解 对于第二维的操作和01背包几 ...

  9. As of ADT 14, resource fields cannot be used as switch cases

        在导入Android Sample的ApiDemos的时候,发现R.id.xx的文件不能够在 switch cases 中使用 在google查询了下,找到以下答案: As of ADT 14 ...

  10. poj 2192 (DP)

    这个题题目意思是给你三个字符串str1,str2,str3.将str3从左自右扫描,去匹配str1和str2中的元素,不可重复,若存在一种匹配方法使得str1和str2都被匹配完全了,则输出yes,否 ...