1、题目描述

2、问题分析

利用递归。

3、代码

 vector<int> preorderTraversal(TreeNode* root) {
vector<int> v;
preBorder(root, v);
return v;
} void preBorder(TreeNode *root, vector<int> &v)
{
if (root == NULL)
return ;
v.push_back(root->val);
preBorder(root->left, v);
preBorder(root->right, v);
}

LeetCode题解之 Binary Tree Preorder Traversal的更多相关文章

  1. 【LeetCode】144. Binary Tree Preorder Traversal (3 solutions)

    Binary Tree Preorder Traversal Given a binary tree, return the preorder traversal of its nodes' valu ...

  2. 【LeetCode】144. Binary Tree Preorder Traversal 解题报告(Python&C++&Java)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 迭代 日期 题目地址:https://leetc ...

  3. 【LeetCode】144. Binary Tree Preorder Traversal

    题目: Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binar ...

  4. LeetCode OJ 144. Binary Tree Preorder Traversal

    Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tr ...

  5. LeetCode OJ:Binary Tree Preorder Traversal(前序遍历二叉树)

    Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tr ...

  6. 【LEETCODE OJ】Binary Tree Preorder Traversal

    Problem Link: http://oj.leetcode.com/problems/binary-tree-preorder-traversal/ Even iterative solutio ...

  7. leetcode 题解:Binary Tree Inorder Traversal (二叉树的中序遍历)

    题目: Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary ...

  8. LeetCode题解之N-ary Tree Preorder Traversal

    1.题目描述 2.问题分析 采用递归方法是标准解法. 3.代码 vector<int> preorder(Node* root) { vector<int> v; preNor ...

  9. LeetCode题解之Binary Tree Postorder Traversal

    1.题目描述 2.问题分析 递归 3.代码 vector<int> postorderTraversal(TreeNode* root) { vector<int> v; po ...

随机推荐

  1. DTCMS部署错误

    1.添加如下节点 <system.webServer> <validation validateIntegratedModeConfiguration="false&quo ...

  2. [Java初探外篇]__关于时间复杂度与空间复杂度

    前言 我们在前面的排序算法的学习中了解到了,排序算法的分类,效率的比较所使用到的判断标准,就包括时间复杂度和空间复杂度,当时因为这两个定义还是比较难以理解的,所以决定单独开一篇文章,记录一下学习的过程 ...

  3. 使用XHProf分析PHP性能瓶颈(一)

    安装xhprof扩展 wget http://pecl.php.net/get/xhprof-0.9.4.tgz tar zxf xhprof-0.9.4.tgz cd xhprof-0.9.4/ex ...

  4. Tomcat笔记:Tomcat的执行流程解析

    Bootstrap的启动 Bootstrap的main方法先new了一个自己的对象(Bootstrap),然后用该对象主要执行了四个方法: init(); setAwait(true); load(a ...

  5. lucene-01-简介

    1, 介绍 hadoop作者开发的 hdfs最开始作为netch的文件存储来使用的 2, 存储结构 lucene快的原因, 是因为添加数据的时候会对数据进行分词, 将分词后的词建立索引, 存储到索引库 ...

  6. C++类型转化小结

    之前面试就有被问过关于使用类型转换的问题,因为主要是做Windows驱动的开发,一直都是纯C语言+汇编,当时真的是只用过C语言的强制类型转换,C语言的强制类型转换(Type Cast)很简单,不管什么 ...

  7. elasticSearch6源码分析(6)http和transport模块

    1.http模块概述 The http module allows to expose Elasticsearch APIs over HTTP. The http mechanism is comp ...

  8. SPA页面初试

    之前一直很好奇,SPA应用到底是怎么实现的,昨天无意间看到了有一篇介绍的文章,就想着来试一下水(以下根据我的理解所写,可能会让你看的云里雾里,如果想加深了解,最好先了解下window.location ...

  9. PBN旁切转弯保护区组图

    旁切转弯是PBN(Performance Based Navigation基于性能导航)中使用频率最高的一种飞行方式,旁切转弯保护区支持最大120°的转弯. 旁切转弯保护区叠加图: 旁切转弯保护区分解 ...

  10. POJ 1258 Agri-Net(Prim算法求解MST)

    题目链接: http://poj.org/problem?id=1258 Description Farmer John has been elected mayor of his town! One ...