char* longestCommonPrefix(char** strs, int strsSize) {
int index=1,min=INT_MAX;
if(strsSize==1) return strs[0];
while(index<strsSize){
int i=0;
while(strs[index-1][i]!=0 && strs[index][i]!=0 && strs[index-1][i]==strs[index][i]){
i++;
}
if(i<min) min =i;
index++;
}
if(min==INT_MAX) return NULL;
char* array=(char*)malloc(sizeof(char)*(min+1));
for(int i=0;i<min;i++) array[i]=strs[0][i];
array[min]=0;
return array;
}
结果:
标签:index,14,strs,char,int,strsSize,最长,前缀 From: https://www.cnblogs.com/llllmz/p/18076036