Advertisement
jinhuang1102

38. Count and Say

Nov 25th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. import itertools
  2.  
  3. class Solution(object):
  4.     def countAndSay(self, n):
  5.         """
  6.        :type n: int
  7.        :rtype: str
  8.        """
  9.         s = '1'
  10.         for _ in range(0, n-1):
  11.             ls = []
  12.             for digit, group in itertools.groupby(s):
  13.                 temp = len(list(group))
  14.                 temp = str(temp) + digit
  15.                 ls.append(temp)
  16.             s = ''.join(ls)
  17.        
  18.         return s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement