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 054243a

Browse filesBrowse files
Merge pull request FazeelUsmani#129 from FazeelUsmani/goodNodes
Create 17_goodNodesinBT.py
2 parents 9407346 + c5f6ba6 commit 054243a
Copy full SHA for 054243a

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.