From 52f610aeae00ebf8a106cedc76f3aee482af9b85 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Tue, 10 Jul 2018 10:05:33 +0800 Subject: [PATCH] Create 104.cpp --- LeetCode-CN/104.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 LeetCode-CN/104.cpp diff --git a/LeetCode-CN/104.cpp b/LeetCode-CN/104.cpp new file mode 100644 index 0000000..08a0d0c --- /dev/null +++ b/LeetCode-CN/104.cpp @@ -0,0 +1,24 @@ +class Solution { +public: + int maxDepth(TreeNode* root) { + if (!root) return 0; + std::queue> bus; + bus.push(std::make_pair(root, 1)); + int hmax = 1; + while (!bus.empty()) + { + std::pair now = bus.front(); + hmax = std::max(hmax, now.second); + bus.pop(); + if (now.first->left) + { + bus.push(std::make_pair(now.first->left, now.second + 1)); + } + if (now.first->right) + { + bus.push(std::make_pair(now.first->right, now.second + 1)); + } + } + return hmax; + } +};