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

class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
int vSize = strs.size();
string result = "";
if(vSize == ) return result;
else if(vSize == ) return strs[]; result = strs[];
int i,j;
for(i = ; i < vSize; i++){
for(j = ; j < result.length() && j < strs[i].length(); j++){
if(strs[i][j] != result[j]) break;
}
result = result.substr(,j); //截取字符串
}
return result;
}
};

14.Longest Common Prefix (String)的更多相关文章

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

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

  2. 14. Longest Common Prefix【leetcode】

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

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

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

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

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

  5. Leetcode 14. Longest Common Prefix(水)

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

  6. leetCode练题——14. Longest Common Prefix

    1.题目 14. Longest Common Prefix   Write a function to find the longest common prefix string amongst a ...

  7. 14. Longest Common Prefix

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

  8. [LeetCode] 14. Longest Common Prefix

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

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

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

随机推荐

  1. Python基础学习----异常

    ''' 异常: 程序在运行的时候,Python的解释器遇到一个错误会停止运行. 并且会提供错误的信息,这就是异常 抛出异常: 程序停止执行并且提示错误信息这个动作就是抛出异常(raise Except ...

  2. L204

    Riding a bike is good exercise and great fun. But what do you do with a bike after you outgrow it? N ...

  3. New Concept English Two 3

    $课文5 无错号之虞 47. Mr.James Scott has a garage in Silbury and now he has just bought another garage in P ...

  4. nmcli 命令的基本使用

    nmcli命令 地址配置工具:nmcli nmcli  device  查看所有网卡的信息 nmcli  device  status 和numcli device 相同 nmcli  device ...

  5. 第8课 goto和void分析

    遭人遗弃的goto: C语言是一种面向过程的结构化语言,其中主要结构有三种,顺序执行.选择执行.循环执行.再复杂的程序也是由这三种结构组合而成的. goto破坏了结构化特性,使程序以第四种方式执行,结 ...

  6. .NET 中让 Task 支持带超时的异步等待

    Task 自带有很多等待任务完成的方法,有的是实例方法,有的是静态方法.有的阻塞,有的不阻塞.不过带超时的方法只有一个,但它是阻塞的. 本文将介绍一个非阻塞的带超时的等待方法.   Task 已有的等 ...

  7. 利用Web Services开发分布式应用

    一.引言 在前面文章中分别介绍了MSMQ和.NET Remoting技术,今天继续分享.NET 平台下另一种分布式技术——Web Services 二.Web Services 详细介绍 2.1 We ...

  8. python 用 __all__ 暴露接口

    非常典型的python的用法 refer to : http://python-china.org/t/725

  9. Rotor envoy control plane 简单试用

    rotor 基于golang 的envoy xds 服务,支持多种集成方式: k8s consul aws dc/os demo试用docker 以及consul 进行环境运行 下载demo 可以试用 ...

  10. Linux中epoll+线程池实现高并发

    服务器并发模型通常可分为单线程和多线程模型,这里的线程通常是指“I/O线程”,即负责I/O操作,协调分配任务的“管理线程”,而实际的请求和任务通常交由所谓“工作者线程”处理.通常多线程模型下,每个线程 ...