Leetcode: Longest Common Prefix
来源:互联网 发布:大数据生态圈 编辑:程序博客网 时间:2024/06/07 23:30
Write a function to find the longest common prefix string amongst an array of strings.
string longestCommonPrefix(vector<string> &strs) { // Start typing your C/C++ solution below // DO NOT write int main() function int row = strs.size();if(row < 1) return "";if(row == 1) return strs[0];int strlength = strs[0].length();for(int i = 1; i < row; ++i)if(strs[i].length() < strlength) strlength = strs[i].length();int count = 0;bool flag = true;for(int i=0; i< strlength && flag; ++i){char commonchar = strs[0][count];int j = 0;for(; j < row; ++j)if(strs[j][count] != commonchar) {flag = false; break;}if((j == row) && (flag = true))count++;}return strs[0].substr(0,count); }
- 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
- 嵌入式学习指南
- java字节分割转换 数据类型转换 文件输入流
- 10-listView视图
- AndroidManifest.xml 网络权限
- 整型数组处理算法(七)重排问题
- Leetcode: Longest Common Prefix
- Android NFC开发实例:学生卡数据读取
- iOS开发 -- IOS7界面兼容,从4.3到7.0兼容的NavigationBar ,IOS7 NavigationBar 适配
- Codeforces Round #202 (Div. 2) B.Color the Fence
- iOS 播放客户端视频
- 12-DispatcherTimer控制进度条的显示
- 字符串反转的七种方法
- Report
- Leetcode: Longest Substring Without Repeating Characters