精華區beta Marginalman 關於我們 聯絡資訊
※ 引述《Rushia (みけねこ的鼻屎)》之銘言: : 38. Count and Say : 數數之後組成下一個字串,直接看例子: : https://assets.leetcode.com/uploads/2020/10/23/countandsay.jpg
: n = 1: return 1 is the base case : n = 2: return count of last entry i.e. 1 1 : n = 3: return count of last entry i.e. two 1's so 21 : n = 4: we have one 2 and one 1 so 1211 : n = 5: , we have one 1 and one 2 and two 1's so -> 111221 : n = 6: we have three 1's, two 2's and one 1 so -> 312211 : n = 7: we have one 3, one 1, two 2's and two 1's -> 13112221 哈哈 這不就是 groupby 嗎 哈哈哈哈哈哈 class Solution: def countAndSay(self, n: int) -> str: count, say = '1', '' for i in range(n-1): for k, v in groupby(count): say += ''.join([str(len(list(v))), k]) count, say = say, '' return count 面試官:你可以不要用那個 groupby 嗎? -- 蛤? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.251.195.223 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1666083015.A.89E.html
Rushia: PYTHON禁止禁止禁止 啊啊啊啊啊啊 10/18 16:51
twosheep0603: 禁止阿阿阿阿阿 10/18 17:39
abcd991276: 禁止禁止 10/18 17:50