精華區beta Marginalman 關於我們 聯絡資訊
Count and say 題目要算數字個數 例如11 就是兩個1所以答案21 21就是 1個2 1個1 所以1211 就迴圈硬解 class Solution { public: string countAndSay(int n) { string ans = "1"; int j = 1, count; while(j < n){ string temp; for (int i = 0; i < ans.size(); i += count){ count = 1; while (ans[i] == ans[i + count]) count++; temp += ('0' + count); temp += ans[i]; } ans = temp; j++; } return ans; } }; ---- Sent from BePTT -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.174.113.203 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1666077854.A.35B.html
pandix: 大師10/18 15:34
JerryChungYC: 大師 不過21是 1211 或 1112 吧10/18 15:39
abcd991276: 打太快打錯10/18 15:41
※ 編輯: abcd991276 (1.174.113.203 臺灣), 10/18/2022 15:42:30