Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ca0ce29

Browse files
committed
阿里在线编程算法题 2020-1-14
1 parent a0220f7 commit ca0ce29

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# @Time : 2020/1/14 11:20
2+
# @Author : Libuda
3+
# @FileName: 找出二叉搜索树第二大的树.py
4+
# @Software: PyCharm
5+
6+
class Tree:
7+
def __init__(self, val, left=None, right=None):
8+
self.val = val
9+
self.left = left
10+
self.right = right
11+
12+
13+
def Solution(root):
14+
if root:
15+
if root.right:
16+
if root.right.right:
17+
return Solution(root.right)
18+
elif root.right.left:
19+
return root.right.left.val
20+
return root.val
21+
elif root.left:
22+
return root.left.val
23+
return None
24+
25+
26+
root = Tree(20)
27+
lv1_1 = Tree(15)
28+
lv1_2 = Tree(25)
29+
lv2_1 = Tree(4)
30+
lv2_2 = Tree(18)
31+
lv2_3 = Tree(23)
32+
lv2_4 = Tree(60)
33+
34+
root.left, root.right = lv1_1, lv1_2
35+
lv1_1.left, lv1_1.right = lv2_1, lv2_2
36+
lv1_2.left, lv1_2.right = lv2_3, lv2_4
37+
38+
res = Solution(root)
39+
40+
print(res)

阿里在线编程算法题/矩阵最小路径和.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def Solution(m):
3636
m[i][j]+=min(m[i-1][j],m[i][j-1])
3737

3838
return m[endx][endy]
39+
40+
3941
"""
4042
动态规划 只需要循环一次 到右下角的最小值=min(左边,上边)+自己的值
4143
4 1 1 1 4 5 6 7

0 commit comments

Comments
 (0)