Skip to content

Commit 418f8a1

Browse files
committed
Time: 0 ms (100.00%), Space: 7 MB (45.24%) - LeetHub
1 parent 3050bc1 commit 418f8a1

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* struct TreeNode {
4+
* int val;
5+
* TreeNode *left;
6+
* TreeNode *right;
7+
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
8+
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
9+
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
10+
* };
11+
*/
12+
class Solution {
13+
public:
14+
int findSecondMinimumValue(TreeNode* root) {
15+
16+
if(root->left == NULL)
17+
return -1;
18+
19+
int l = root->left->val == root->val ? findSecondMinimumValue(root->left) : root->left->val;
20+
int r = root->right->val == root->val ? findSecondMinimumValue(root->right) : root->right->val;
21+
22+
if(l == -1 || r == -1)
23+
return max(l, r);
24+
return min(l,r);
25+
}
26+
};

0 commit comments

Comments
 (0)