使用递归打印二叉树的左视图 java package com.li.jinRiTouTiao; public class PrintLeftView { static class TreeNode{ TreeNode left; TreeNode right; int val; public TreeNode(int val) { this.val = val; } } int layer=0; //定义一个全局变量,最大层数layer, depth是递归的深度. public void pri
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. Example: Input: [1,2,3,null,5,null,4] Output: [1, 3, 4] Explanation: 1 <--- / \ 2 3 <--- \ \ 5 4 <--- 思
199. 二叉树的右视图 199. Binary Tree Right Side View 题目描述 给定一棵二叉树,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值. 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. LeetCode19
题目描述:从上到下打印二叉树的节点,同一层的从左到右打印 思路:采用队列来存储单层的节点,然后通过删除队列的头结点操作,依次遍历每一层. 代码为: import java.util.ArrayList; /** public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; } } */ //用ArrayList