Path to given node

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

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dhanarajappu

Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.