From 028990b3533b49dae58d12887f55e263823595b4 Mon Sep 17 00:00:00 2001 From: Stackingrule <38368554+Stackingrule@users.noreply.github.com> Date: Mon, 21 Dec 2020 21:50:18 +0800 Subject: [PATCH] feat:add Solution.cpp for 0111. Minimum Depth of Binary Tree --- .../0111.Minimum Depth of Binary Tree/Solution.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 solution/0100-0199/0111.Minimum Depth of Binary Tree/Solution.cpp diff --git a/solution/0100-0199/0111.Minimum Depth of Binary Tree/Solution.cpp b/solution/0100-0199/0111.Minimum Depth of Binary Tree/Solution.cpp new file mode 100644 index 0000000000000..6dbe2254ca619 --- /dev/null +++ b/solution/0100-0199/0111.Minimum Depth of Binary Tree/Solution.cpp @@ -0,0 +1,9 @@ +class Solution { +public: + int minDepth(TreeNode* root) { + if (!root) return 0; + if (!root->left) return 1 + minDepth(root->right); + if (!root->right) return 1 + minDepth(root->left); + return 1 + min(minDepth(root->left), minDepth(root->right)); + } +}; \ No newline at end of file