一次AC

字符串就是:count+char

 1 class Solution:
 2     # @return a string
 3     def countAndSay(self, n):
 4         str = "1"
 5         for i in range(n-1):
 6             tmp = str
 7             str = ""
 8             c = tmp[0]
 9             cnt = 1
10             for j in range(1,len(tmp)):
11                 if tmp[j] == tmp[j-1]:
12                     cnt += 1
13                 else:
14                     str += ("%d"%cnt + tmp[j-1])
15                     cnt = 1
16             str += ("%d"%cnt + tmp[len(tmp)-1])
17         return str

 

相关文章:

  • 2021-07-08
  • 2021-08-30
  • 2022-12-23
猜你喜欢
  • 2021-10-15
  • 2021-06-05
  • 2022-03-04
  • 2021-08-31
  • 2021-08-23
相关资源
相似解决方案