【leetcode】第14题:Longest Common Prefix
2016-03-16 09:06
162 查看
代码如下:public static String findLongestPrefix(String[ ] str ){
String result = new String("");
if(str != null && str.length>0){
Arrays.sort(str);
}
String temp = new String();
temp = str[0] ;
for(int i = 0;i<temp.length(); i++){
if(str[str.length-1].length()>i&&str[str.length-1].charAt(i)==temp.charAt(i)){
result += temp.charAt(i);
}
else{
return result;
}
}
return result;
}
相关文章推荐
- 月薪3万的程序员都避开了哪些坑
- Eclipse快捷键
- C#-using用法详解
- js年月日三级联动
- 【代码笔记】提醒时间的选择
- 按天统计HealthKit数据
- Core Data使用
- 用原型代替PRD时,原型应该包含哪些内容
- 【代码笔记】提醒时间的选择
- Android图片编码机制深度解析(Bitmap,Skia,libJpeg)
- 增加表空间大小及imp、impdp、sqlldr导入命令
- 面试题-和为 n 连续正数序列
- CGI编程学习
- SAP号码段表及相关操作T-CODE
- 好博客
- 51单片机——I2C总线
- 关于this究竟代表的案例
- android学习路线
- 阿里云服务器防攻击
- Java经典设计模式之十一种行为型模式(附实例和详解)