1、题目描述
2、问题分析
使用层序遍历
3、代码
vector<int> v;
vector<int> rightSideView(TreeNode* root) {
if (root == NULL)
return v; queue<TreeNode*> q;
q.push(root); while (!q.empty()) {
int size = q.size();
for(int i = ; i < size; i++) {
TreeNode *node = q.front();
if (node->left != NULL)
q.push(node->left);
if (node->right != NULL)
q.push(node->right); if (i == size - )
v.push_back(node->val);
q.pop();
}
} return v; }