Leetcode: Binary Tree Inorder Traversal

中序遍历


代码:

#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