leetcode103
class Solution {
public:
vector<vector<int>> zigzagLevelOrder(TreeNode* root) {
vector<vector<int>> V;
if (root != NULL)
{
int i = ;
queue<TreeNode*> Q;
Q.push(root);
while (!Q.empty())
{
vector<TreeNode*> T;
vector<int> v;
while (!Q.empty())
{
TreeNode* node = Q.front();
Q.pop();
T.push_back(node);
v.push_back(node->val);
}
if (i % == )
{
vector<int> vv;
for (int j = v.size() - ; j >= ; j--)
{
vv.push_back(v[j]);
}
V.push_back(vv);
}
else
{
V.push_back(v);
}
for (auto t : T)
{
if (t->left != NULL)
{
Q.push(t->left);
}
if (t->right != NULL)
{
Q.push(t->right);
}
}
i++;
}
}
return V;
}
};
leetcode103的更多相关文章
- [Swift]LeetCode103. 二叉树的锯齿形层次遍历 | Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...
- (二叉树 BFS) leetcode103. Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...
- LeetCode103 BinaryTreeZigzagLevelOrderTraversal(二叉树Z形层次遍历) Java题解
题目: Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from lef ...
- 32-3题:LeetCode103. Binary Tree Zigzag Level Order Traversal锯齿形层次遍历/之字形打印二叉树
题目 给定一个二叉树,返回其节点值的锯齿形层次遍历.(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行). 例如: 给定二叉树 [3,9,20,null,null,15,7], 3 ...
- LeetCode103. 二叉树的锯齿形层次遍历
103. 二叉树的锯齿形层次遍历 描述 给定一个二叉树,返回其节点值的锯齿形层次遍历.(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行). 示例 例如,给定二叉树: [3,9,2 ...
- Leetcode103. Binary Tree Zigzag Level Order Traversal二叉树的锯齿形层次遍历
给定一个二叉树,返回其节点值的锯齿形层次遍历.(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行). 例如: 给定二叉树 [3,9,20,null,null,15,7], 3 / ...
- LeetCode103 Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...
- leetcode103:permutations-ii
题目描述 给出一组可能包含重复项的数字,返回该组数字的所有排列 例如: [1,1,2]的排列如下: [1,1,2],[1,2,1], [2,1,1]. Given a collection of nu ...
- LeetCode 103. 二叉树的锯齿形层次遍历(Binary Tree Zigzag Level Order Traversal)
103. 二叉树的锯齿形层次遍历 103. Binary Tree Zigzag Level Order Traversal 题目描述 给定一个二叉树,返回其节点值的锯齿形层次遍历.(即先从左往右,再 ...
随机推荐
- Rails 5 Test Prescriptions 第8章 Integration Testing with Capybara and Cucumber
Capybara: A complete reference is available atrubydoc.info. 集成测试就是把局部的程序组合起来测试. 端到端测试是一个特殊的集成测试,覆盖了 ...
- Learn Rails5.2 Bundler ; Forms
如果一个Rubyer想要提供一个功能或某个程序或程序的集合给其他Rubyer使用,这个Rubyer可以创建一个package,这个package就叫做gems. 可以通过gem install安装. ...
- Android中Tablayout设置下划线宽度 和 dp和px之间进行相互转换
开发中遇到了一个问题,Tablayout设置下换线长度,看了点资料,分享给大家. 效果图: 直接贴代码(要在tabLayout添加完所有的tab后调用) public vo ...
- CentOS下安装Python-pip
1.安装epel-release软件包:自动配置yum的软件仓库,弥补centos内容更新有时比较滞后或是一些扩展的源没有. yum -y install epel-release 2.安装pytho ...
- 尺取法拓展——POJ3320
#include <iostream> #include <cstdio> #include <algorithm> #include <set> #i ...
- Arachni web扫描工具
扫描工具-Arachni from:https://blog.csdn.net/zixuanfy/article/details/52818527 ./arachni_console ...
- laravel中数据库迁移的使用:
创建数据库迁移文件: php artisan make:migration create_links_table 创建完表之后,设置字段: public function up() { Schema: ...
- bzoj2325
题解: 树链剖分 和普通的树链剖分不一样,这里的线段树不只是要记录x-y的和 而是要记录x左到y左,x左到y右,x右到y左,x右到y右 然后就可以了 代码: #include<bits/stdc ...
- phpstudy2017版本的nginx 支持laravel 5.X配置
之前做开发和学习一直用phpstudy的mysql服务,确实很方便,开箱即用.QQ群交流:697028234 现在分享一下最新版本的phpstudy2017 laravel环境配置. 最新版的phps ...
- 彻底弄懂jQuery事件原理二
上一篇说到,我们在最外层API的on,off,tiggler,triggerHandler调用的是event方法的add,remove和tirgger方法,本篇就来介绍event辅助类 \ 先放个图, ...