[LintCode] 最长公共前缀
2015-06-29 15:25
405 查看
class Solution { public: /** * @param strs: A list of strings * @return: The longest common prefix */ string longestCommonPrefix(vector<string> &strs) { // write your code here string lcp = ""; if (strs.empty()) return lcp; for (int i = 0; i < (int)strs[0].length(); i++) { int pos = lcp.length(); char letter = strs[0][pos]; for (int j = 1; j < (int)strs.size(); j++) if (strs[j].length() == pos || strs[j][pos] != letter) return lcp; lcp += letter; } return lcp; } };
相关文章推荐
- list_style li 9646 的点
- 百度新接口,让网页秒收
- linux下iptraf和netperf的应用
- 什么是DSL
- 4.17&4.18
- PullToRefreshListView局部刷新
- Count and Say
- ios 直角和圆角 并存
- FrameLayout(框架布局)
- gradle的maven plugin使用
- acdream 1210 Chinese Girls' Amusement (打表找规律)
- 常用css+css3集锦
- 指针函数与函数指针的区别
- 黑马程序员——java基础之IO流
- Jmeter http请求 Demo(压测Elasticsearch)
- windows系统还原打不开怎么办?
- 最小二乘支持向量机(LSSVM)简述
- Linux下网络流量实时监控工具 大全
- C语言指针
- NSString什么时候用copy,什么时候用strong