1 vector<int> res; 2 int key1, key2; 3 4 void traverse(TreeNode * root){//采用前序遍历 5 if(root == NULL) 6 return; 7 if(key1 <= root->val && key2 >= root->val)//满足条件的就存入 8 res.push_back(root->val); 9 traverse(root->left); 10 traverse(root->right);
1 vector<int> res; 2 int key1, key2; 3 4 void traverse(TreeNode * root){//采用前序遍历 5 if(root == NULL) 6 return; 7 if(key1 <= root->val && key2 >= root->val)//满足条件的就存入 8 res.push_back(root->val); 9 traverse(root->left); 10 traverse(root->right);