-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountAndSayREC.py
35 lines (27 loc) · 960 Bytes
/
countAndSayREC.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# playing with append instead of using suffix[i] = prefix/suffix but I need to reverse the list which takes time
class Solution:
def countAndSay(self, n):
if n == 1:
return "1"
s = self.countAndSay(n-1)
pinga = len(s)
i = 0
myStr = ""
while i < pinga:
number = s[i]
countChars = 0
while i < pinga and s[i] == number:
countChars += 1
i += 1
#trick happens here
myStr += str(countChars) + number
return myStr
# def countAndSay(self, n):
# s = "1"
# for i in range(n-1):
# # s becomes the result of whatever digit(s)
# # you are processing. in this case "num" becomes 11
# s = self.numToSay(s)
# return s
myVar = Solution()
myVar.countAndSay(7)