Skip to content

Commit 84310c5

Browse files
committed
update
1 parent eee78b6 commit 84310c5

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

P103. 外观数列.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
![algo42](./images/algo42.jpg)
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+
last_ind, last_digit = stack.pop()
21+
count = str(ind-last_ind+1)
22+
cur += (count+str(last_digit))
23+
24+
pre = cur
25+
return pre
26+
```

images/algo42.jpg

51.6 KB
Loading

0 commit comments

Comments
 (0)