count and say leetcode @python
https://leetcode.com/submissions/detail/44515521/
class Solution(object): def count(self,s): res = "" count = 0; cur = "#" for i in s: if i!=cur: if cur!='#': res+=str(count)+cur cur=i count=1 else: count+=1 res+=str(count)+cur return res def countAndSay(self, n): """ :type n: int :rtype: str """ s='1' for i in range(2,n+1): s = self.count(s) return s
每天一小步,人生一大步!Good luck~
浙公网安备 33010602011771号