首页 > 其他 > 详细

Count and Say

时间:2014-10-08 23:27:17      阅读:301      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!