My Solution For this Question


  • 0
    B
    public List<Integer> rightSideView(TreeNode root) {
    		List<Integer> list = new ArrayList<>();
    		if (root==null) {
    			return list;
    		}
    		list.add(root.val);
    		list.addAll(rightSideView(root.right));
    		List<Integer> tmpLeft = rightSideView(root.left);
    		if (tmpLeft.size()>list.size()-1) {
    			int leftSize = tmpLeft.size();
    			for(int i=list.size()-1;i<leftSize;i++){
    				list.add(tmpLeft.get(i));
    			}
    		}
    		return list;
    	}

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.