Open Ni-Guvara opened 1 year ago
class Solution { public: vector<int> rightSideView(TreeNode* root) { vector<int> ret; queue<TreeNode *> aux; if(root) aux.push(root); while(!aux.empty()) { int len = aux.size(); ret.push_back(aux.back()->val); for(int idx = 0; idx < len; idx++ ) { TreeNode * node = aux.front(); aux.pop(); if(node->left) aux.push(node->left); if(node->right) aux.push(node->right); } } return ret; } };