Chinaunix首页 | 论坛 | 博客
  • 博客访问: 254836
  • 博文数量: 170
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1709
  • 用 户 组: 普通用户
  • 注册时间: 2014-05-06 18:01
文章分类

全部博文(170)

文章存档

2016年(11)

2015年(130)

2014年(29)

分类: Java

2015-03-05 09:16:01

Write a function to find the longest common prefix string amongst an array of strings.

public class LongestCommonPrefix {
public String longestCommonPrefix(String[] strs) {
if(strs.length==0)
return "";
String tempString=strs[0];
    for (int i = 1; i < strs.length; i++) {
    int j=0;
while(j if(tempString.charAt(j)!=strs[i].charAt(j))
break;
++j;
}
tempString=tempString.substring(0, j);
    }  
    return tempString;
}
}

阅读(645) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~