class Solution: def countAndSay(self, n: int) -> str: seq = "1" for i in range(n-1): seq = self.getNext(seq) return seq def getNext(self, seq): i, next_seq = 0, ‘‘ while i < len(seq): count = 1 while i+1 <len(seq) and seq[i] == seq[i+1]: count += 1 i += 1 next_seq += str(count) + seq[i] i += 1 return next_seq
原文地址:https://www.cnblogs.com/WJZheng/p/11401928.html
时间: 2024-10-10 21:53:52