Re: [閒聊] 每日LeetCode已回收

看板Marginalman作者 (QQ)時間3年前 (2022/10/18 15:24), 3年前編輯推噓2(201)
留言3則, 3人參與, 3年前最新討論串50/719 (看更多)
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

10/18 15:34, 3年前 , 1F
大師
10/18 15:34, 1F

10/18 15:39, 3年前 , 2F
大師 不過21是 1211 或 1112 吧
10/18 15:39, 2F

10/18 15:41, 3年前 , 3F
打太快打錯
10/18 15:41, 3F
※ 編輯: abcd991276 (1.174.113.203 臺灣), 10/18/2022 15:42:30
文章代碼(AID): #1ZJbIUDR (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1ZJbIUDR (Marginalman)