char * reverseWords(char * s){
int len=strlen(s);
char *re=(char*)malloc(sizeof(char)*(len+1));
int count=0;
int i=0;
while(s[i]!='\0')
if(s[i]!=' '){
i++;
count++;
}
else{
re[i]=' ';
for(int j=i-count,m=0;j<i;j++,m++)
re[j]=s[i-1-m];
i++;
count=0;
}
re[i]='\0';
for(int j=i-count,m=0;j<i;j++,m++)
re[j]=s[i-1-m];
i++;
count=0;
return re;
}
leetcode打卡49
最新推荐文章于 2022-11-12 12:02:37 发布