设为首页 加入收藏

TOP

Leetcode_Longest Common Prefix
2015-07-20 17:19:33 来源: 作者: 【 】 浏览:2
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 01:19:11)
·为什么C标准库没有链 (2025-12-27 01:19:08)
·玩转C语言和数据结构 (2025-12-27 01:19:05)
·MySQL 基础入门视频 (2025-12-26 23:20:22)
·小白入门:MySQL超详 (2025-12-26 23:20:19)