From 633b16bbe30e064af73944476d108cd6d904fde7 Mon Sep 17 00:00:00 2001 From: Yash Goyal <63150203+yash-goyal8@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:49:45 +0530 Subject: [PATCH] Create 513 Find_Bottom_left_Tree_value.cpp solution to the leetcode problem (513) in cpp --- 513 Find_Bottom_left_Tree_value.cpp | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 513 Find_Bottom_left_Tree_value.cpp diff --git a/513 Find_Bottom_left_Tree_value.cpp b/513 Find_Bottom_left_Tree_value.cpp new file mode 100644 index 0000000..4ac57bb --- /dev/null +++ b/513 Find_Bottom_left_Tree_value.cpp @@ -0,0 +1,36 @@ +/** + * Definition for a binary tree node. + * struct TreeNode { + * int val; + * TreeNode *left; + * TreeNode *right; + * TreeNode() : val(0), left(nullptr), right(nullptr) {} + * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} + * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} + * }; + */ +class Solution { +public: + int findBottomLeftValue(TreeNode* root) { + queue que; + que.push(root); + vector> res; + while(!que.empty()){ + int size = que.size(); + vector row; + for(int i=0;ival); + if(front->left!=NULL){ + que.push(front->left); + } + if(front->right!=NULL){ + que.push(front->right); + } + } + res.push_back(row); + } + return res[res.size()-1][0]; + } +};