精華區beta Marginalman 關於我們 聯絡資訊
3223. Minimum Length of String After Operations 思路: 如果字串長度小於3直接回傳原字串長度 否則遍歷字串,只要有個數大於3的字母就將個數減2直到小於3,再將全部字母個數加總輸 出 C int minimumLength(char* s) { if(strlen(s) < 3) return strlen(s); int count[200] = {0}; int length = 0; for(int i = 0; s[i] != '\0'; i++){ count[s[i]]++; } for(int i = 95; i <= 122; i++){ while(count[i] >= 3){ count[i] -= 2; } length += count[i]; } return length; } -- 芙芙搖 https://i.imgur.com/MaRqFO6.gif 生氣芙 https://i.imgur.com/KBa6Y4W.gif 真芙了 https://i.imgur.com/bxBemfT.gif 芙芙笑 https://i.imgur.com/uEnaGdP.gif 嗚嗚嗚 https://i.imgur.com/NCYm7ne.gif -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.141.220.186 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1736795143.A.F5B.html
Meaverzt: 凌晨三點還在卷:0 01/14 12:05