[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 ...
随机推荐
- Linux监控二之cacti简单安装部署
目录 cacti简单部署 1 环境依赖包部署 1 1. cacti中文版0.8e搭建 2 2. cacti安装向导 url:http://192.168.200.243/ ...
- vue 项目中使用mock假数据实现前后端分离
也是查了很多的资料,整理出来.实现了前后端的分离,用到的技术vue-cli,webpack,node,json-server.首先全局安装json-server cnpm i json-server ...
- 【JS】实时监控页面,input框数值自动求和
需求: 有一个页面需要将input框填入的各个费用自动相加,添加到“合计费用”里. 解决方案: 使用jquery的blur实践,每个费用的Input框检测到失去焦点时,将所有的input框数值相加求和 ...
- [转载]本地配置的 *.dev,*.app域名 在谷歌浏览器中总是自动转跳到https上,导致不能访问?
本地开发环境 .dev 不正常,找到文章mark一下 转自:https://segmentfault.com/q/1010000012339191
- 精通SpringBoot--Spring事件 Application Event
Spring的事件为Bean与Bean之间的通信提供了支持,当我们系统中某个Spring管理的Bean处理完某件事后,希望让其他Bean收到通知并作出相应的处理,这时可以让其他Bean监听当前这个Be ...
- 【luminate primordial】苏州之行
测试了reader 07版 更主要的是第一次坐了高铁 还不错 路上看到下雨的时候都是水顺着玻璃平着流 好厉害的样子 6个人去的6个人回 今儿开会 老板不太满意 小随意 对我来说,收获感觉还是不小的,使 ...
- 洛谷 P1736 创意吃鱼法(多维DP)
题目描述 回到家中的猫猫把三桶鱼全部转移到了她那长方形大池子中,然后开始思考:到底要以何种方法吃鱼呢(猫猫就是这么可爱,吃鱼也要想好吃法 ^_*).她发现,把大池子视为01矩阵(0表示对应位置无鱼,1 ...
- 51nod_1199 树的先跟遍历+区间更新树状数组
题目是中文,所以不讲题意 做法顺序如下: 使用先跟遍历,把整棵树平铺到一维平面中 使用自己整的区间更新树状数组模板进行相关操作. http://www.cnblogs.com/rikka/p/7359 ...
- 笔记-python-standard library-9.6 random
笔记-python-standard library-9.6 random 1. random source code:Lib/random.py 1.1. functions for ...
- 阿里云服务器+Tomcat项目+mysql 发布项目全过程
这个博客管理系统折腾我好几天了. 总结一下整个过程吧! 1.首先这个博客在tomcat下 windows系统可以完全跑起来了,无论是前台或者后台都能实现所有的功能. 2.然后我买了一个域名jasonj ...