中序遍历

代码:

#include <iostream>
#include <vector>
using namespace std;struct TreeNode {int val;TreeNode *left;TreeNode *right;TreeNode(int x) : val(x), left(NULL), right(NULL) {}};class Solution {
public:vector<int> record;void inorderTravel(TreeNode *root) {if(root->left)inorderTravel(root->left);record.push_back(root->val);if(root->right)inorderTravel(root->right);}vector<int> inorderTraversal(TreeNode *root) {record.clear();inorderTravel(root);return record;}
};

  

转载于:https://www.cnblogs.com/xinsheng/p/3459891.html

Leetcode: Binary Tree Inorder Traversal相关推荐

  1. LeetCode Binary Tree Inorder Traversal

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

  2. [leetcode]Binary Tree Inorder Traversal

    二叉树的中序遍历非递归版本,采用的是wiki百科上的办法.果然简洁,而且和先序有异曲同工之妙,先序只用push右节点,中序只用push中节点.除此之外还有个更改TreeNode加一个visited的b ...

  3. 【二叉树迭代版中序遍历】LeetCode 94. Binary Tree Inorder Traversal

    LeetCode 94. Binary Tree Inorder Traversal Solution1:递归版 二叉树的中序遍历递归版是很简单的,中序遍历的迭代版需要特殊记一下! 迭代版链接:htt ...

  4. LeetCode 94. Binary Tree Inorder Traversal

    94. Binary Tree Inorder Traversal Given a binary tree, return the inorder traversal of its nodes' va ...

  5. [LeetCode] Binary Tree Postorder Traversal 二叉树的后序遍历

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

  6. 15 二叉树的中序遍历(Binary Tree Inorder Traversal)

    文章目录 1 题目 2 描述 3 解决方案 3.1 递归算法 3.1.1 遍历法(Traverse) 思路 源码 3.1.2 分治法(Devide And Conquer) 思路 源码 3.2 非递归 ...

  7. [LeetCode]:94:Binary Tree Inorder Traversal

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

  8. leetcode[94]Binary Tree Inorder Traversal

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

  9. [swift] LeetCode 94. Binary Tree Inorder Traversal

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

最新文章

  1. linux 公私钥生成,[c++,openssl,RSA] linux下编程实现生成公私钥对_1
  2. 如何使用Autopano Video Pro进行全景视频拼接?
  3. 解决linux登录后总是时间过会就断开(解决ssh登录后闲置时间过长而断开连接)...
  4. 在ubuntu中安装minicom时出现device /dev/tty8 is locked解决办法
  5. MAC下快速打开指定目录
  6. php后门木马常用命令
  7. 接口测试常用工具及测试方法(新手篇)
  8. 简单易懂之python 中的map,filter,reduce用法
  9. 使用七牛实现静态页面的上传
  10. java实训文献_java实训论文参考文献写作指导
  11. LitePal遇到的坑
  12. 电工与电子技术和电子电工的区别
  13. 十进制进制法_十进制转换成二进制及二进制转换成十进制是如何转换的?
  14. SWAT | SWAT源码编译
  15. 香蕉树上第十根芭蕉——深度好文-为什么要写博客
  16. Google Earth Engine ——QGIS中计算加权质心
  17. 老毛桃u盘重装win7教程
  18. SQLyog连接linux数据库问题
  19. 【高级篇 / System】(7.0) ❀ 07. HA 下配置核心交换机 (下) ❀ FortiGate 防火墙
  20. JAVA从入门到起飞

热门文章

  1. 数字在排序数组中的出现次数
  2. python实现文件传输_Python实现基于HTTP文件传输实例
  3. 傅里叶变换及其应用 pdf_应用傅里叶-小波检测方式的并联型有源电力滤波器,电能质量高...
  4. 雅思口语:填充词(句子)
  5. 解决Tensorflow2.0出现:AttributeError: module ‘tensorflow‘ has no attribute ‘get_default_graph‘的问题
  6. 今日恐慌与贪婪指数为78 贪婪程度有所缓解
  7. Ren获得Zcash技术咨询委员会资助,将在币安智能链上启动RenZEC流动性引导计划
  8. 英国汇丰银行拒绝为客户处理加密货币交易
  9. SAP License:SAP顾问你算哪根葱?
  10. 一条案例:如何选择合适的第三方数据源