I wrote out more than one hour written, but the author always stuck with for a long time to find the bug did not find (toss two hours), temporarily abandoned.
The following is a positive solution, and my thinking is similar, but relatively small points, not a bug
char*longestCommonPrefix(char**strs,int strsSize){if(strsSize ==0){return"";}if(strsSize ==1)return*strs;int len =0;for(int i =0; i <strlen(strs[0]); i++){if(strs[0][i]== strs[1][i]&& strs[0][i]!='\0')
len++;elsebreak;}for(int i =1; i < strsSize -1; i++){if(len>strlen(strs[i+1]))
len =strlen(strs[i +1]);for(int j = len -1; j >=0; j--){if(strs[i][j]!= strs[i +1][j])
len = j;}if(len ==0)break;}char*result =(char*)malloc((len +1)*sizeof(char));strncpy(result, strs[0], len);
result[len]='\0';return result;}
The following is a bug in the code needs to be improved: