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
原文地址:https://www.cnblogs.com/yalphait/p/10428090.html