14. Longest Common Prefix
来源:互联网 发布:windows 批处理 多进程 编辑:程序博客网 时间:2024/06/01 14:41
Write a function to find the longest common prefix string amongst an array of strings.
题意:最长公共前缀
class Solution {public: string longestCommonPrefix(vector<string>& strs) { int len = strs.size(); if(len == 0) return ""; string lcp = strs[0]; for(int i = 1; i < len; ++i){ int l1 = lcp.length(); int l2 = strs[i].length(); int j; for(j = 0; j < l1 && j < l2; ++j){ if(strs[i][j] != lcp[j]){ lcp = strs[i].substr(0, j); break; } } if(j == l2) lcp = strs[i]; } return lcp; }};
阅读全文
0 0
- 14. Longest Common Prefix
- 14.Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 使用python实现深度神经网络 1
- gcc g++版本降级
- react+express +materialui模板
- 云技术简介
- 图片轮播
- 14. Longest Common Prefix
- 使用python实现深度神经网络 2
- apt-get update 出现错误
- 图——拓扑排序(Graph
- 使用python实现深度神经网络 3
- 16、不一样的C++系列--const对象与类成员的知识点
- windows下svn的使用
- 英语单词(1)
- 我的博客即将入驻"云栖社区",撑腰技术同行一同入驻