Re: [閒聊] 每日LeetCode已回收
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
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
討論串 (同標題文章)
完整討論串 (本文為第 50 之 719 篇):