• 19.2.24 [LeetCode 94] Binary Tree Inorder Traversal


    Given a binary tree, return the inorder traversal of its nodes' values.

    Example:

    Input: [1,null,2,3]
       1
        
         2
        /
       3
    
    Output: [1,3,2]
     1 class Solution {
     2 public:
     3     void build(TreeNode*root, vector<int>&ans) {
     4         if (root == NULL)return;
     5         build(root->left, ans);
     6         ans.push_back(root->val);
     7         build(root->right, ans);
     8     }
     9     vector<int> inorderTraversal(TreeNode* root) {
    10         vector<int>ans;
    11         build(root, ans);
    12         return ans;
    13     }
    14 };
    View Code
  • 相关阅读:
    NYOJ 205
    NYOJ 187
    NYOJ 105
    NUOJ 88
    NYOJ 70
    LL(1)算法
    MATLAB的一些基础知识
    Ubuntu raid5+lvm实验
    空间滤波
    认识weblogic的各个机构
  • 原文地址:https://www.cnblogs.com/yalphait/p/10428090.html
Copyright © 2020-2023  润新知