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 eee78b6 commit 84310c5Copy full SHA for 84310c5
P103. 外观数列.md
@@ -0,0 +1,26 @@
1
+
2
+
3
+```
4
+class Solution:
5
+ def countAndSay(self, n: int) -> str:
6
+ pre = '1'
7
+ for i in range(n-1):
8
+ stack = []
9
+ count = ''
10
+ cur = ''
11
+ for ind, digit in enumerate(pre):
12
+ if stack and digit == stack[-1][1]:
13
+ continue
14
+ if stack and digit != stack[-1][1]:
15
+ last_ind, last_digit = stack.pop()
16
+ count = str(ind-last_ind)
17
+ cur += (count+str(last_digit))
18
+ stack.append([ind, digit])
19
20
21
+ count = str(ind-last_ind+1)
22
23
24
+ pre = cur
25
+ return pre
26
images/algo42.jpg
51.6 KB
0 commit comments