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

  

class Solution {
public:
string longestCommonPrefix(vector<string> &strs) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
string result="";
if(strs.size() == ) return result ; string first = strs[] ; for(int i = ; i < first.size() ;i++)
{
char c = first[i] ;
for(int j = ; j< strs.size(); j++)
if(i > strs[j].size() - || c != strs[j][i])
return result; result+=c;
} return result ;
}
};

LeetCode_Longest Common Prefix的更多相关文章

  1. [转][LeetCode]Longest Common Prefix ——求字符串的最长公共前缀

    题记: 这道题不难但是很有意思,有两种解题思路,可以说一种是横向扫描,一种是纵向扫描. 横向扫描:遍历所有字符串,每次跟当前得出的最长公共前缀串进行对比,不断修正,最后得出最长公共前缀串. 纵向扫描: ...

  2. [LeetCode] Longest Common Prefix 最长共同前缀

    Write a function to find the longest common prefix string amongst an array of strings. 这道题让我们求一系列字符串 ...

  3. 【leetcode】Longest Common Prefix

    题目简述: Write a function to find the longest common prefix string amongst an array of strings. 解题思路: c ...

  4. LintCode 78:Longest Common Prefix

      public class Solution { /** * @param strs: A list of strings * @return: The longest common prefix ...

  5. [LintCode] Longest Common Prefix 最长共同前缀

    Given k strings, find the longest common prefix (LCP). Have you met this question in a real intervie ...

  6. 14. Longest Common Prefix

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

  7. Leetcode Longest Common Prefix

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

  8. [LeetCode] 14. Longest Common Prefix

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

  9. No.014:Longest Common Prefix

    问题: Write a function to find the longest common prefix string amongst an array of strings. 官方难度: Eas ...

随机推荐

  1. Android中focusable属性的妙用——底层按钮的实现

    http://www.cnblogs.com/kofi1122/archive/2011/03/22/1991828.html http://www.juziku.com/weizhishi/3077 ...

  2. android添加edittext后布局就不好用

    在布局添加控件手动添加还是拖的添加,添加edittext后布局就不好用,其他控件好用,然后就说下面这段话 Exception raised during rendering: java.lang.Sy ...

  3. 测试jsp

    一. get.jsp <%@ page contentType="text/html;charset=UTF-8"%> <%@ page import=" ...

  4. WIN8共享文件 详细设置

    原文地址:http://jingyan.baidu.com/article/75ab0bcbff4274d6864db2f5.html win8共享文件设置 详细教程 | 浏览:6987 | 更新:2 ...

  5. MySQL数据备份之mysqldump

      mysqldump常用于MySQL数据库逻辑备份 1.各种用法说明 A. 最简单的用法: mysqldump -uroot -pPassword [database name] > [dum ...

  6. mysql的日志

    是否启用了日志mysql>show variables like ‘log_bin’; 怎样知道当前的日志mysql> show master status; 看二进制日志文件用mysql ...

  7. 使用WebRTC实现电脑与手机通过浏览器进行视频通话

    最近一直在研究WebRTC,做了一个小项目:www.meet58.com,这个项目利用WebRTC.WebSocket可以让各种设备只通过浏览器进行视频聊天,无论是电脑.手机或者是平板.下面就是手机和 ...

  8. kaggle之手写体识别

    kaggle地址 数据预览 首先载入数据集 import pandas as pd import numpy as np train = pd.read_csv('/Users/frank/Docum ...

  9. Android Studio 导入Eclipse工程

    eclipse:workspace对应多个project:而android studio是project对应多个module:故,在android studio中的工程project实际上是eclip ...

  10. 纯css实现下拉菜单

    今天给大家分享一个纯html+css实现的下拉菜单.在此声明一点,源码并非出自本人之手,是同项目组一兄弟PLUTO写的.好东西嘛,所以果断拿出来和大家分享.如果有更好的想法或者建议,一定记得留言哦!好 ...