设为首页 加入收藏

TOP

Leetcode_Longest Common Prefix
2015-07-20 17:19:33 来源: 作者: 【 】 浏览:3
Tags:Leetcode_Longest Common Prefix

题意为找到所有字符串的最长的共同前缀。

思路:

1.先遍历一遍,得出最短字符串的长度

2.对每一个字符串均与第一个字符串比较,出现不同,则得出最长公共前缀到此结束

class Solution {
public:
    string longestCommonPrefix(vector
  
    &strs) {
		
		int len=strs.size();
		int min=INT_MAX;
		string commomPrefix;
		if(len==0)
			return commomPrefix;
		for(int k=0;k
   
    

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇[BestCoder] Round #11 下一篇c++11深入学习

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·有没有哪些高效的c++ (2025-12-27 08:20:57)
·Socket 编程时 Accep (2025-12-27 08:20:54)
·计算机网络知识点总 (2025-12-27 08:20:52)
·一篇说人话的文章, (2025-12-27 07:50:09)
·Python Web框架哪家 (2025-12-27 07:50:06)