Re: [闲聊] 每日leetcode

楼主: JIWP (JIWP)   2024-03-11 23:00:49
你版都好猛,剩我刚才才想起来今天每日还没写了
C code怎么这么难写
char* customSortString(char* order, char* s) {
char *res=(char*)malloc(sizeof(char)*(strlen(s)+1));
res[strlen(s)]='\0';
int *rec=(int*)calloc(26,sizeof(int)),idx=0;
for (int i=0;i<strlen(s);i++){
rec[s[i]-97]++;
}
for (int i=0;i<strlen(order);i++){
memset(res+idx,order[i],rec[order[i]-97]);
idx+=rec[order[i]-97];
rec[order[i]-97]=0;
}
for (int i=0;i<26;i++){
if (rec[i]!=0){
memset(res+idx,i+97,rec[i]);
idx+=rec[i];
}
}
return res;
}
作者: yam276 ('_')   2024-03-11 23:01:00
我讨厌malloc跟new
作者: oin1104 (是oin的说)   2024-03-11 23:01:00
你要转职了没
作者: DJYOSHITAKA (Evans)   2024-03-11 23:05:00
大师
作者: NCKUEECS (小惠我婆)   2024-03-11 23:17:00
恨C

Links booklink

Contact Us: admin [ a t ] ucptt.com