[LeetCode] Binary Tree Postorder Traversal dfs,深度搜索
#include <iostream>
#include <vector>
using namespace std; /**
* Definition for binary tree
*/
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
}; class Solution {
public:
vector<int> postorderTraversal(TreeNode *root) {
vector<int> ret;
if(root==NULL) return ret;
help_f(root,ret);
return ret;
}
void help_f(TreeNode *node,vector<int> &ret)
{
if(node==NULL) return;
help_f(node->left,ret);
help_f(node->right,ret);
ret.push_back(node->val);
}
}; int main()
{
return ;
}
[LeetCode] Binary Tree Postorder Traversal dfs,深度搜索的更多相关文章
- LeetCode: Binary Tree Postorder Traversal 解题报告
Binary Tree Postorder Traversal Given a binary tree, return the postorder traversal of its nodes' va ...
- [LeetCode] Binary Tree Postorder Traversal 二叉树的后序遍历
Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary ...
- Leetcode Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary t ...
- [Leetcode] Binary tree postorder traversal二叉树后序遍历
Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary t ...
- LeetCode——Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary ...
- LeetCode: Binary Tree Postorder Traversal [145]
[题目] Given a binary tree, return the postorder traversal of its nodes' values. For example: Given bi ...
- LeetCode Binary Tree Postorder Traversal(数据结构)
题意: 用迭代法输出一棵二叉树的后序遍历结果. 思路: (1)用两个栈,一个存指针,一个存标记,表示该指针当前已经访问过哪些孩子了. /** * Definition for a binary tre ...
- leetcode Binary Tree Postorder Traversal python
# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = ...
- leetcode Binary Tree Postorder Traversal 二叉树后续遍历
先给出递归版本的实现方法,有时间再弄个循环版的.代码如下: /** * Definition for binary tree * struct TreeNode { * int val; * Tree ...
随机推荐
- IE console报错
需要注意的是,使用console对象查看对象信息,在IE8浏览器下未打开开发人员工具(F12)的情况下 会报'console'未定义错误. 解决办法:1.打开开发人员调试工具(F12) ...
- Python学习笔记(二):数据类型
一.python中的数据类型 python中的数据类型包括:整型.浮点型.布尔型.字符串类型 整型(int)和浮点型(float) Python中的整型只有int,没有short.long:浮点型fl ...
- Charles Babbage【查尔斯·巴贝奇】
Charles Babbage When Babbage was working at Cambridge, a new idea occurred to him. 巴贝奇在剑桥工作的时候,脑海中有了 ...
- 命令执行sql
从外网把数据库用导出脚本的方式导出来了,280M的样子,导是导出来了,但是在本机执行sql脚本的时候,直接就是out of memory,之前执行60M的脚本没出过这问题,直接双击打开.sql脚本文件 ...
- SpringMVC基本概念
DispatcherServlet:MVC的前端控制器,浏览器用户的请求经过DispatcherServlet的分发,到达合适的controller,生产业务数据所需要的model,model通过Di ...
- 44、gridview实现下拉刷新、上拉加载更多(最简单实现上下拉操作的开源工程!)
1.工程加入以下两个文件夹:(参考:https://github.com/jingchenUSTC/PullToRefreshAndLoad) (待会我会将demo打包上传) 2.这个demo只有一个 ...
- 【Reverse Nodes in k-Group】cpp
题目: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list ...
- 使用bat命令实现拖动快速安装APK包
平时安装APK包,每次都要打命令adb install *********** 很繁琐,网上找到一个用BAT命令快速安装的方法 在桌面创建一个bat文件,输入: @echo off title i ...
- MongoDB用PCRE正则表达式
介绍 下面说明 PCRE 所支持的正则表达式的语法和语义.Perl 文档和很多其它书中也解说了正则表达式,有的书中有很多例子.Jeffrey Friedl 写的“Mastering Regular E ...
- php 实现栈与队列
<?php class queueOp{ /* * 队尾入队 * Return:处理之后队列的元素个数 */ public function tailEnquque($arr,$val){ re ...