//// Created by liushuai on 2021年1月17日.//#include "treeRightView.h"void treeRightView(TreeNode* root,std::vector<int>& result){if(!root)return ;else{std::queue<TreeNode*> nodes;if(root)nodes.push(root);int count = 0;std::vector<std::vector<int>> final;while (!nodes.empty()){std::vector<int> layers;int node_size = nodes.size();for(int i=0;i<node_size;i++){TreeNode* current = nodes.front();nodes.pop();layers.push_back(current->val);if(current->left)nodes.push(current->left);if(current->right)nodes.push(current->right);}final.push_back(layers);}for(auto elem:final){result.push_back(elem[elem.size()-1]);}}}std::vector<int> treeRightView(std::vector<int>& a,std::vector<int>& b){TreeNode* root = reConstructBinaryTree(a,b);std::vector<int> result;treeRightView(root,result);return result;}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。