Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c5f6ba6

Browse filesBrowse files
authored
Create 17_goodNodesinBT.py
1 parent 03d4b88 commit c5f6ba6
Copy full SHA for c5f6ba6

File tree

Expand file treeCollapse file tree

1 file changed

+11
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-0
lines changed
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def __init__(self):
3+
self.count = 0
4+
5+
def goodNodes(self, root):
6+
for child in filter(None, [root.left, root.right]):
7+
self.count += child.val >= root.val
8+
child.val = max(child.val, root.val)
9+
self.goodNodes(child)
10+
11+
return self.count + 1

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.