Could anyone please help me find why am i getting a runtime error in my code


#1

string Solution::longestCommonPrefix(vector &A) {
string sameSubArray = A[0];
int count=0;
for(int i=0;i<A.size()-1;i++){
for(int j=0;j<A[i].length();j++){
if(A[i][j]!=A[i+1][j]){
count++;
// cout<<count<<endl;
}
if(count!=0){
if(j==0){
sameSubArray.clear();
}
else{
for(int k=0;k<j;k++){
sameSubArray[k]=A[i][k];
}
break;
}
}
}
}
return sameSubArray;
}