public class Solution { public String longestCommonPrefix(String[] strs) { int size=strs.length; if(size==0) return ""; int index=0; boolean flag=true; while(true) { char a='x'; for(int i=0;i<size;i++) { if(index>=strs[i].length()) { flag=false; break; } if(i==0) { a=strs[i].charAt(index); } else { if(a!=strs[i].charAt(index)) { flag=false; break; } } } if(flag==false) break; index++; } String res=strs[0].substring(0,index); return res; } }