bool backspaceCompare(char* s, char* t) {
int ns=strlen(s),nt=strlen(t);
int heads=0,headt=0,index=0;
while(index<ns){
if(s[index]!='#'){
s[heads++]=s[index++];
}else{
heads--;
if(heads<0) heads=0;
index++;
}
}
index=0;
while(index<nt){
if(t[index]!='#'){
t[headt++]=t[index++];
}else{
headt--;
if(headt<0) headt=0;
index++;
}
}
if(heads==headt && heads==0) return true;
if(heads!=headt) return false;
for(int i=0;i<heads;i++){
printf("%c %c ",s[i],t[i]);
if(s[i]!=t[i]) return false;
}
return true;
}
标签:index,844,int,char,字符串,strlen,退格 From: https://www.cnblogs.com/llllmz/p/18080971