1、输出二叉树的所有路径(从根到所有叶子节点)【回溯】
void getAllPath(TreeNode* root, std::vector<std::vector<int>>& all_paths) {
static std::vector<int> path; // 这里是static的
if (nullptr == root) { return; }
path.push_back(root->val);
if (root->left == nullptr && root->right == nullptr) {
all_paths.push_back(path);
}
getAllPath(root->left, all_paths);
getAllPath(root->right, all_paths);
path.pop_back();
}