Check out the problem description here. Path to Given Node - InterviewBit
Path to Given Node - Problem Description Given a Binary Tree A containing N nodes. You need to find the path from Root…www.interviewbit.com Solution class Solution:
def solve(self, A, B):
ds=[]
self.rec(A,B,ds)
return ds
def rec(self,root,B,ds):
if root ==None :
return False
ds.append(root.val)
if root.val == B:
return True
if self.rec(root.left,B,ds) or self.rec(root.right,B,ds):
return True
ds.pop(-1)
return False