From 8b9548cb6f277e685198874f9a9973706db75d05 Mon Sep 17 00:00:00 2001 From: Ace-Krypton Date: Wed, 20 Sep 2023 17:18:43 +0200 Subject: [PATCH] Added Construct Binary Tree from Preorder and Inorder Traversal --- .../include/solution.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Medium/ConstructBinaryTreeFromPreorderAndInorderTraversal/include/solution.hpp b/Medium/ConstructBinaryTreeFromPreorderAndInorderTraversal/include/solution.hpp index c98ef6d..9832d99 100644 --- a/Medium/ConstructBinaryTreeFromPreorderAndInorderTraversal/include/solution.hpp +++ b/Medium/ConstructBinaryTreeFromPreorderAndInorderTraversal/include/solution.hpp @@ -16,15 +16,16 @@ struct TreeNode { class Solution { public: static auto build_tree(const std::vector &preorder, - const std::vector &inorder) -> TreeNode* { + const std::vector &inorder) -> TreeNode* { auto pre = preorder.begin(); auto in = inorder.begin(); - std::function construct = [&](int32_t stop) -> TreeNode* { + std::function construct = + [&](const int32_t stop) -> TreeNode* { if (pre == preorder.end() || *in == stop) return (TreeNode*)nullptr; auto *node = new TreeNode{*(pre++)}; node->left = construct(node->value); - assert (*in == node->value); + assert(*in == node->value); in++; node->right = construct(stop); return node;