码迷,mamicode.com
首页 > 其他好文 > 详细

Count and Say

时间:2014-10-09 00:28:07      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   sp   div   c   on   log   

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

 

Count and Say

标签:style   blog   color   io   sp   div   c   on   log   

原文地址:http://www.cnblogs.com/iois/p/4011468.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!