# [Leetcode]Binary Tree Right Side View(TAT)

Binary Tree Right Side View My Submissions Question
Total Accepted: 26870 Total Submissions: 87779 Difficulty: Medium
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].

Credits:
Special thanks to @amrsaqr for adding this problem and creating all test cases.

Subscribe to see which companies asked this question

/**
* Definition for a binary tree node.
* struct TreeNode {
*     int val;
*     TreeNode *left;
*     TreeNode *right;
*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<int> rightSideView(TreeNode* root) {
vector<int> res;
//vector<int> tem;
if(!root)   return res;
queue<TreeNode*> q;
q.push(root);
while(!q.empty()){
for(int i = 0,len = q.size();i < len;++i){
TreeNode* t = q.front();
q.pop();
if(i == len - 1){
res.push_back(t->val);
}
if(t->left) q.push(t->left);
if(t->right)    q.push(t->right);
}
//res.push_back(*(tem.end() - 1));
//tem.clear();
}
return res;
}
};

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

2015-04-06 10:33:34

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

2015-04-23 21:23:06

#### [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（二叉树右侧视图）

2016-05-04 03:32:35

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

2016-08-24 14:51:46

#### LeetCode-199. Binary Tree Right Side View (JAVA)（二叉树最右侧结点)

2017-04-17 17:06:09

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

2015-05-06 21:55:56

#### 【LeetCode】199. Binary Tree Right Side View-二叉树右视图结点

2017-03-28 10:37:45

#### leetcode 199. Binary Tree Right Side View-树的右视图|递归|非递归|Java|Python

2016-05-31 22:20:00