Leetcode: Longest Common Prefix
来源:互联网 发布:什么是棋牌源码 编辑:程序博客网 时间:2024/06/16 22:35
Write a function to find the longest common prefix string amongst an array of strings.
public class Solution { public String longestCommonPrefix(String[] strs) { if (strs == null) { return null; } if (strs.length == 0) { return ""; } String res = strs[0]; for (int i = 1; i < strs.length; i++) { String curr = strs[i]; StringBuilder sb = new StringBuilder(); int j = 0; while (j < res.length() && j < curr.length() && res.charAt(j) == curr.charAt(j)) { sb.append(res.charAt(j)); j++; } res = sb.toString(); } return res; }}
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
- Linux下网卡驱动和版本信息
- ubuntu乱码
- hdu 5037 Galaxy 鞍山现场赛题目
- 在线建表sql转Java类,提高编程效率
- Android中检查、监听电量和充电状态的方法
- Leetcode: Longest Common Prefix
- C++内存管理
- ListFragment中ListVew中点击事件的响应
- 二.cocoa touch 之 TextKit
- Maven仓库汇总及私服
- Java:Socket通信
- 显著提升程序员身心健康和工作效率的装备有哪些?
- 第9周项目3输出星号图(3)
- vim最重要常用的一些命令