递归
class Solution {
public:
vector<int> ret;
vector<int> preorder(Node* root) {
findw(root);
return ret;
}
void findw(Node*root){
if( root!= nullptr ){
ret.push_back( root->val );
for( auto i:root->children ){
findw( i );
}
}
}
};
递归
class Solution {
public:
vector<int> ret;
vector<int> preorder(Node* root) {
findw(root);
return ret;
}
void findw(Node*root){
if( root!= nullptr ){
ret.push_back( root->val );
for( auto i:root->children ){
findw( i );
}
}
}
};