标签:
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 && strs.length()==0){
return "";
}
int len=strs.length();
String pre=strs[0]; for(int i=1; i<len; i++){ int j=0; while(j<pre.length() && j<strs[i].length() && strs[i].charAt(j)==pre.charAt(j)){ j++; } if(j==0){ return ""; } pre=pre.substring(0, j); } return pre; } }
LeetCode-Longest Common Prefix
标签:
原文地址:http://www.cnblogs.com/incrediblechangshuo/p/5353640.html