首页 > 代码库 > Count and Say

Count and Say

LeetCode


 

 1 class Solution: 2     # @return a string 3     def countAndSay(self, n): 4         if n==1: 5             return "1" 6         else: 7             output="" 8             res=self.countAndSay(n-1) 9             n=110             i=111             while i<len(res):12                 if res[i-1]==res[i]:13                     n=n+114                 else:15                     output=output+str(n)+res[i-1]16                     n=117                 i=i+118             output=output+str(n)+res[i-1]19             return output

 

Count and Say