zoukankan      html  css  js  c++  java
  • lintcode 二叉树后序遍历

     1 /**
     2  * Definition of TreeNode:
     3  * class TreeNode {
     4  * public:
     5  *     int val;
     6  *     TreeNode *left, *right;
     7  *     TreeNode(int val) {
     8  *         this->val = val;
     9  *         this->left = this->right = NULL;
    10  *     }
    11  * }
    12  */
    13 
    14 //递归
    15 class Solution {
    16 public:
    17     /*
    18      * @param root: A Tree
    19      * @return: Postorder in ArrayList which contains node values.
    20      */
    21      
    22      void inorder(TreeNode *root, vector<int> &result) {
    23          if (root->left != NULL) {
    24              inorder(root->left, result);
    25          }
    26          if (root->right != NULL) {
    27              inorder(root->right, result);
    28          }
    29          result.push_back(root->val);
    30      }
    31      
    32     vector<int> postorderTraversal(TreeNode * root) {
    33         // write your code here
    34         vector<int> result;
    35         if (root == NULL) {
    36             return result;
    37         }
    38         inorder(root, result);
    39         return result;
    40     }
    41 };
  • 相关阅读:
    20200304(10)
    20200303Tuesday(9)
    词根词缀explicit(8)
    词根词缀(7)
    20200303(6)
    什么是ring0-ring3
    20200301a
    mark字体大全
    评估评价 提高专项(5)
    图的广度优先遍历算法
  • 原文地址:https://www.cnblogs.com/gousheng/p/7391294.html
Copyright © 2011-2022 走看看