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. python流程控制语句 ifelse - 3

    #! /usr/bin/python x = input ('please inut a integer:') x = int(x) : print ('你输入了一个负数') elif x == : ...

  2. openfire插件开发1

    http://www.cnblogs.com/hoojo/archive/2013/03/29/openfire_plugin_chatlogs_plugin_.html http://www.cnb ...

  3. 使用ExtJs实现文件下载

    文件下载,是不可以直接通过Ext.Ajax.Request来实现的.一般的,可以通过创建一个隐藏的form表单来实现.具体代码以及代码注释如下: if (!Ext.fly('downForm')){ ...

  4. POJ 1322 Chocolate(母函数)

    题目链接:http://poj.org/problem?id=1322 题意: 思路: double C[N][N]; void init() { C[0][0]=1; int i,j; for(i= ...

  5. FTP命令详解

    FTP的命令行格式为:ftp -v -d -i -n -g [主机IP或者主机名],其中 -v显示远程服务器的所有响应信息: -n限制ftp的自动登录,即不使用: .n etrc文件: -d使用调试方 ...

  6. HeadFirst jsp 02 (体系结构)

    当请求到来时, 必须有人实例化 servlet, 或者至少建立一个新的线程来处理这个请求. 必须有人调用 servlet 的 doPost()或 doGet()方法. 另外还的有人管理 servlet ...

  7. OpenStack介绍

    简介 OpenStack是一个开源的云计算管理平台项目,由几个主要的组件组合起来完成具体工作.OpenStack支持几乎所有类型的云环境,项目目标是提供实施简单.可大规模扩展.丰富.标准统一的云计算管 ...

  8. 用 eclipse ndk 编译 cocos2d-x for Android

    Android 环境搭建不详述,,可以google,,, 我用的coco2dx 是 2.14 ,2.14 用 create_project.py 脚本创建工程,Python环境配置也是很简单,这里了不 ...

  9. hibernate lazy=false annotation设置

    工程报错如下: org.hibernate.LazyInitializationException: could not initialize proxy - no Session 解决方法: 在类的 ...

  10. An AnnotationConfiguration instance is required to use

    An AnnotationConfiguration instance is required to use <mapping class="jebe7282/study/hibern ...