Binary Tree Level Order Traversal II 描述 Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root). For example
题目连接:Leetcode 107 Binary Tree Level Order Traversal II 解题思路:参考Leetcode 102 和103,只要最后将102中的答案翻转一下即可。 /*** Definition for a binary tree node.* struct TreeNode {* int val;* TreeNode *left;*
107. 二叉树的层序遍历 II 这道题要求进行自底向上的层序遍历,可以先使用正序层序遍历的方式对树进行遍历,然后将每一层的遍历结果放入一个栈数据结构中,等遍历完成后,将栈数据结构中的每一层的节点再弹出加入到结果集合,即可将原先栈中的数据顺序反转,实现自底向上的层序遍历 public List<List<Integer>> levelOrderBottom(TreeNode root) {Li
#include<bits/stdc++.h>using namespace std;typedef long long LL;const int N=500000+10;//a 是原来的数组,temp 是临时数组int a[N],temp[N];//因为元素有 500000 个,逆序对的数目可能会非常多//假设按照降序排列,那么将有 n+(n-1)+(n-2)+...+1//(1+n)*n