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=1 10 i=1 11 while i<len(res): 12 if res[i-1]==res[i]: 13 n=n+1 14 else: 15 output=output+str(n)+res[i-1] 16 n=1 17 i=i+1 18 output=output+str(n)+res[i-1] 19 return output