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

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Simple Sorting algorithm learning notes

How to publish Android Library on Bintray/JCenter using with github code.

Fixing VSCode Color Bug on Linux

Python — the programming language of Machine Learning

Coaching managers on leading agile teams

The Process: A blueprint to creating digital services that serves millions

Distributing workflows across a cluster

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.

More from Medium

Pre work: Wire frames

Some fun with PLC

CS371p Spring 2022 Week #12: Sumedh Kandadai

INTRODUCTION TO polyfarm.me smart contract project.