Skip to content

Commit bddb8c5

Browse files
committed
563. Binary Tree Tilt
1 parent b0d31f4 commit bddb8c5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

binary-tree-tilt.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Runtime: 79 ms
2+
class Solution(object):
3+
def findTilt(self, root):
4+
self.res = 0
5+
6+
def solve(root):
7+
if not root:
8+
return 0
9+
10+
a = solve(root.left)
11+
b = solve(root.right)
12+
self.res += abs(a - b)
13+
return a + b + root.val
14+
15+
solve(root)
16+
return self.res

0 commit comments

Comments
 (0)