Skip to content

Commit 601efd9

Browse files
committed
添加了示例代码
1 parent c2c2786 commit 601efd9

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

Day31-35/code/homework01.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# 经典递归求解问题:
2+
# 1. 迷宫寻路
3+
# 2. 汉诺塔(梵塔)
4+
# 3. 骑士周游
5+
# 4. 八皇后
6+
7+
8+
def f(n: int, m=1) -> int:
9+
if n == 0 or n == 1:
10+
return m
11+
return f(n - 1, n * m)
12+
13+
14+
def sum(n: int) -> int:
15+
if n == 1:
16+
return 1
17+
return n + sum(n - 1)
18+
19+
20+
def steps(n: int, m={}) -> int:
21+
if n < 0:
22+
return 0
23+
elif n == 0:
24+
return 1
25+
else:
26+
try:
27+
return m[n]
28+
except:
29+
m[n] = steps(n - 1) + steps(n - 2) + steps(n - 3)
30+
return m[n]
31+
32+
33+
def list_depth(items: list) -> int:
34+
max_depth = 1 if isinstance(items, list) else 0
35+
if max_depth:
36+
for item in items:
37+
if isinstance(item, list):
38+
max_depth = max(max_depth, list_depth(item) + 1)
39+
return max_depth
40+
41+
42+
43+
def main():
44+
mylist = [1, ['a', ['b', ['c']]],[100, [200, 300, [400, [500, [600, [700]]]]]]]
45+
thylist = [[], [[[]]], [[], []]]
46+
print(list_depth(mylist))
47+
print(list_depth(thylist))
48+
49+
50+
if __name__ == '__main__':
51+
main()

Day41-55/res/Django-Flowchart.png

540 KB
Loading

Day41-55/res/Django-MTV.png

142 KB
Loading

0 commit comments

Comments
 (0)