leetcode Longest Common Prefix
来源:互联网 发布:c语言程序小游戏 编辑:程序博客网 时间:2024/06/09 22:18
Write a function to find the longest common prefix string amongst an array of strings.
思想很简单,就是边界问题的处理,采用了re=strs[0],避免边界处理
class Solution {
public:
string longestCommonPrefix(vector<string> &strs) {
int len=strs.size();
if(len==0) return "";
string re=strs[0];
for(int i=0;i<len;i++){
re=sub(strs[i],re);
}
return re;
}
public:
string sub(string str1,string str2){
string re="";
int i=0,len1=str1.length(),len2=str2.length();
while(i<len1&&i<len2&&str1[i]==str2[i]){
re+=str1[i];
i++;
}
return re;
}
};
0 0
- LeetCode: Longest Common Prefix
- LeetCode Longest Common Prefix
- LeetCode : Longest Common Prefix
- [Leetcode] Longest Common Prefix
- [LeetCode] Longest Common Prefix
- [LeetCode]Longest Common Prefix
- LeetCode-Longest Common Prefix
- [LeetCode] Longest Common Prefix
- LeetCode - Longest Common Prefix
- leetcode Longest Common Prefix
- LeetCode | Longest Common Prefix
- Leetcode: Longest Common Prefix
- LeetCode: Longest Common Prefix
- 【LeetCode】Longest Common Prefix
- [LeetCode] Longest Common Prefix
- [LeetCode]Longest Common Prefix
- leetcode: Longest Common Prefix
- LeetCode Longest Common Prefix
- shell中判断变量是否为整型,字符,字符串等的函数
- 练习1-3
- 动景科技(UC浏览器)与合一信息技术(优酷网)不正当竞争案管辖权异议裁定书
- Nyoj 745 蚂蚁的难题(二)
- 体验继承
- leetcode Longest Common Prefix
- unsigned int与int相加问题
- [Wikioi 1025][NOIP 2003普及组]数字游戏
- 算数表达式求值
- Oracle中TO_DATE TO_CHAR格式
- 编码实现环状单向链表(尾指针直接指向头指针,中间没有空节点),去除连续的重复元素的操作
- Android 中使用 XML 中的 fragment 心得
- 线性表的链式存储(单链表)的c语言实现
- 字符串问题python实现(一)