kucheasysa

Algoverse_adesh_14

Jun 10th, 2024
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. class Solution:
  2.     def count(self,n,word):
  3.         if n==0:
  4.             return word
  5.         d = []
  6.         i = 0
  7.         while i<len(word):
  8.             j = i
  9.             count = 0
  10.             while j<len(word) and word[i]==word[j]:
  11.                 count +=1
  12.                 j +=1
  13.             d.append((word[i],count))
  14.             i = j
  15.         word = ''
  16.         for key,val in d:
  17.             word +=(str(val)+key)
  18.         return self.count(n-1,word)
  19.  
  20.     def countAndSay(self, n: int) -> str:
  21.         if n==1:
  22.             return '1'
  23.         return self.count(n-1,'1')
Advertisement
Add Comment
Please, Sign In to add comment