哎哟我擦。用递归让我AC了还不算我过,题目前面没打勾,对我这种有强迫症的人来说,好痛苦。回头想想别的办法。
class Solution {
public:
vector
vector
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
ans.clear();
fun(root);
return ans;
}
void fun(TreeNode *root)
{
if(root != NULL)
{
ans.push_back(root->val);
if(root->left != NULL)
fun(root->left);
if(root->right != NULL)
fun(root->right);
}
}
};