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

【思路】非递归实现

public class Solution {
public List<Integer> rightSideView(TreeNode root) {
List<Integer> res = new ArrayList<Integer>();
if (root == null) return res;
while (!queue.isEmpty()) {
int n = queue.size();
while(n-- > 0) {
root = queue.poll();
}
}
return res;
}
}
210 / 210 test cases passed. Runtime: 2 ms  Your runtime beats 47.48% of javasubmissions.

import Queue
class Solution(object):
def rightSideView(self, root):
"""
:type root: TreeNode
:rtype: List[int]
"""
if root == None : return []
queue, res = Queue.Queue(),[]
queue.put(root)
while not queue.empty() :
n = queue.qsize()
while (n > 0) :
root = queue.get()
if root.left : queue.put(root.left)
if root.right : queue.put(root.right)
if n == 1 : res.append(root.val)
n -= 1
return res
210 / 210 test cases passed. Runtime: 68 ms  Your runtime beats 15.41% of pythonsubmissions.

【思路】递归实现

public class Solution {
public List<Integer> rightSideView(TreeNode root) {
List<Integer> res = new ArrayList<Integer>();
dfs(root, res, 0);
return res;
}
private void dfs(TreeNode root, List<Integer> res, int level) {
if (root == null) return;
if (level == res.size()) {
}
dfs(root.right, res, level+1);
dfs(root.left, res, level+1);
}
}
210 / 210 test cases passed. Runtime: 1 ms  Your runtime beats 84.55% of javasubmissions.

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

2017-03-28 10:37:45

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

2016-05-04 03:32:35

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

2017-04-17 17:06:09

#### Leetcode 199 Binary Tree Right Side View 二叉树右视图

2015-08-05 21:40:39

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

2015-04-09 19:41:15

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

2015-04-23 21:23:06

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

2015-04-06 10:33:34

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

2015-04-09 14:32:29

#### Leetcode 226: Invert Binary Tree(二叉树反转 递归、非递归实现)

2015-06-13 14:41:43

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

2015-04-15 19:11:49

## 不良信息举报

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