Skip to content

Commit 8b78814

Browse files
committed
111
1 parent aa91dc4 commit 8b78814

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Leetcode刷题记录
2323
+ No.95 [cpp](cpp/95.cpp)
2424
+ No.77 [python](python/77.py)
2525
+ No.97 [python](python/97.py)
26+
+ No.111 [cpp](cpp/111.cpp) easy
2627
+ No.529 [cpp](cpp/529.cpp)
2728
+ No.733 [cpp](cpp/733.cpp)
2829

cpp/111.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* struct TreeNode {
4+
* int val;
5+
* TreeNode *left;
6+
* TreeNode *right;
7+
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
8+
* };
9+
*/
10+
class Solution {
11+
public:
12+
int minDepth(TreeNode* root) {
13+
if (!root) return 0;
14+
if (!(root->left && root->right)) {
15+
if (root->left) return minDepth(root->left) + 1;
16+
if (root->right) return minDepth(root->right) + 1;
17+
}
18+
return min(minDepth(root->left), minDepth(root->right)) + 1;
19+
}
20+
};

0 commit comments

Comments
 (0)