标签:leetcode
public class Solution { public String longestCommonPrefix(String[] strs) { if(strs.length == 0) { return ""; } int size = strs[0].length(); for(int i=0; i<strs.length; i++) { if(strs[i].length()<size) { size = strs[i].length(); } } if(size == 0) { return ""; } StringBuffer sb = new StringBuffer(); for(int j=0; j<size; j++) { for(int i=1; i<strs.length;i++) { if(strs[0].charAt(j)!=strs[i].charAt(j)) return sb.toString(); } sb.append(strs[0].charAt(j)); } return sb.toString(); } }
标签:leetcode
原文地址:http://blog.csdn.net/huakaiba/article/details/45968823