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;
    }
};
                    
                
                
            
        
浙公网安备 33010602011771号