###### Binary Tree Right Side View
1. 问题

Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.

For example:
Given the following binary tree,

   1            <---
/   \
2     3         <---
\     \
5     4       <---


You should return [1, 3, 4].

2. 解答
class Solution1 {
public:
vector<int> rightSideView(TreeNode* root) {
vector<int> res;

while(root)
{
res.push_back(root->val);
TreeNode *f1;

if(root->right==NULL)
{
f1=root->left;
if(f1==NULL) break;
}
else
f1=root->right;

root=f1;
}

return res;
}
};

class Solution {
public:
vector<int> rightSideView(TreeNode *root) {
vector<int> ans;
if (root == nullptr) return ans;
queue<TreeNode*> que;
que.push(root);
TreeNode* curr;
while(!que.empty()) {
int cnt = que.size();
for (int i = 0; i < cnt; i++) {
curr = que.front(); que.pop();
if (curr->left) {
que.push(curr->left);
}
if (curr->right) {
que.push(curr->right);
}
}
ans.push_back(curr->val);
}
return ans;
}
};

#### 【LeetCode】Binary Tree Right Side View 解题报告

2015-04-06 10:33:34

#### [JAVA]LeetCode199 Binary Tree Right Side View

2015-04-09 19:41:15

#### leetcode-199 Binary Tree Right Side View

2015-04-09 14:32:29

#### Leetcode 199: Binary Tree Right Side View

2015-04-23 21:23:06

#### LeetCode Binary Tree Right Side View

2015-05-25 14:37:25

#### Binary Tree Right Side View —— Leetcode（精巧的方法，第二遍）

2015-05-06 21:55:56

#### 199. Binary Tree Right Side View Leetcode Python

2015-04-15 19:11:49

#### LeetCode 199. Binary Tree Right Side View（二叉树右侧视图）

2016-05-04 03:32:35

#### LeetCode:Binary Tree Right Side View

2015-04-04 22:50:28

#### Leetcode 199 Binary Tree Right Side View

2017-03-13 15:34:42

## 不良信息举报

Binary Tree Right Side View