Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
451 B
1
Indexable
Never
bool findElement(TreeNode *root, int key, vector<int> &path) {
    if (root == NULL) return false;
    
    path.push_back(root -> val);
    
    if (root -> val == key
    || findElement(root -> left, key, path)
    || findElement(root -> right, key, path))
        return true;
        
    path.pop_back();
    return false;
}


vector<int> Solution::solve(TreeNode* A, int B) {
    vector<int> path;
    findElement(A, B, path);
    return path;
}