We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3b46508 commit e4b9a2cCopy full SHA for e4b9a2c
leetcode/python/strings/count_and_say.py
@@ -0,0 +1,33 @@
1
+# Solves LeetCode question 38. Count and Say
2
+
3
+class Solution(object):
4
+ def countAndSay(self, n):
5
+ """
6
+ :type n: int
7
+ :rtype: str
8
9
+ s = "1"
10
+ if n == 1:
11
+ return s
12
+ for i in range(2,n+1):
13
+ j = 0
14
+ temp = ""
15
+ curr = ""
16
+ count = 0
17
+ while j<len(s):
18
+ if curr =="":
19
+ curr=s[j]
20
+ count=1
21
+ j+=1
22
+ elif curr == s[j]:
23
+ count+=1
24
25
+ else:
26
+ temp+= str(count) + curr
27
+ curr=""
28
29
+ temp+=str(count) + curr
30
+ s=temp
31
32
+ob1 = Solution()
33
+print(ob1.countAndSay(6))
0 commit comments