class Solution { public: string longestCommonPrefix(vector<string> &strs) { int size = strs.size(); if(size==0) return ""; if(size==1) return strs[0]; string result = ""; int i,j; for(j=0;;j++) { for(i=0;i<size-1;i++) { if(strs[i].length()<=j) break; if(strs[i][j]==strs[i+1][j]) continue; else break; } if(i!=size-1) break; else result += strs[i][j]; } return result; } };