Re: [閒聊] 每日leetcode

看板Marginalman作者 (神楽めあ的錢包)時間1年前 (2024/03/11 23:00), 編輯推噓2(202)
留言4則, 4人參與, 1年前最新討論串38/1548 (看更多)
你版都好猛,剩我剛才才想起來今天每日還沒寫了 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; } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.72.69.200 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1710169251.A.93C.html

03/11 23:01, 1年前 , 1F
我討厭malloc跟new
03/11 23:01, 1F

03/11 23:01, 1年前 , 2F
你要轉職了沒
03/11 23:01, 2F

03/11 23:05, 1年前 , 3F
大師
03/11 23:05, 3F

03/11 23:17, 1年前 , 4F
恨C
03/11 23:17, 4F
文章代碼(AID): #1bxnoZay (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1bxnoZay (Marginalman)