Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Definition for binary tree
- * struct TreeNode {
- * int val;
- * TreeNode *left;
- * TreeNode *right;
- * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
- * };
- */
- bool findthepath(TreeNode* A, vector<int> &vec, int B){
- if(A == NULL){
- return false;
- }
- if(findthepath(A->left, vec, B) || findthepath(A->right, vec, B) || A->val == B){
- vec.push_back(A->val);
- return true;
- }
- return false;
- }
- vector<int> Solution::solve(TreeNode* A, int B) {
- vector<int> path;
- findthepath(A, path, B);
- reverse(path.begin(), path.end());
- return path;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement