力扣上的题:https://leetcode.cn/problems/longest-common-prefix/
然后是我的代码
char* longestCommonPrefix(char ** strs, int strsSize){
if(strsSize == 0){
return "";
}
char* ptr = strs[0];
int i = 0, j = 0;
for (; i < strsSize; ++i) {
while(ptr[j] != '\0' && strs[i][j] != '\0' && ptr[j] == strs[i][j]){
j++;
}
ptr[j] = '\0';
}
return ptr;
}
int main() {
char* v[4] = {"flower", "0low", "loy"};
printf("%s", longestCommonPrefix(v,3));
}
问题是这条代码能在力扣上跑在我电脑上的CLion就跑不了
退出代码是 -1073741819 (0xC0000005)