Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit7c71ac4

Browse files
Add 1448 in c language
1 parent825a25b commit7c71ac4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X.
3+
Return the number of good nodes in the binary tree.
4+
Time: O(n)
5+
Space: O(log(h)) Where h is the height of the tree
6+
*/
7+
8+
intnbGood(structTreeNode*root,intm) {
9+
if (root==NULL)
10+
return0;
11+
if (root->val >=m)
12+
return1+nbGood(root->left,root->val)+nbGood(root->right,root->val);
13+
returnnbGood(root->left,m)+nbGood(root->right,m);
14+
}
15+
16+
intgoodNodes(structTreeNode*root){
17+
returnnbGood(root,INT_MIN);
18+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp