filmov
tv
Print all nodes that don't have sibling || BT-3 || GFG
Показать описание
#geeksforgeeks
#coding
#cp
#competitive
#competitivecoding
#User function Template for python3
'''
class Node:
def __init__(self, val):
'''
#if every node has a sibling we have to return [-1]
# else we have to return a sorted list containing all the elements
# which dont have a sibling
# that is they are the lone child of their parents
# : - (
def add(root,ans):
#then just recursively call the funtion
# for both left and the righ tchild
else:
#append that into the answer list and recursively call
# the function again for their only child
def noSibling(root): #this is the main fnction
# code here
ans = [] #this is the answer array which we will return
add(root,ans) #this is the utility function which returns
# the required list
if ans==[]: # if every node has a sibling
ans = [-1] #[=1]
return ans
#coding
#cp
#competitive
#competitivecoding
#User function Template for python3
'''
class Node:
def __init__(self, val):
'''
#if every node has a sibling we have to return [-1]
# else we have to return a sorted list containing all the elements
# which dont have a sibling
# that is they are the lone child of their parents
# : - (
def add(root,ans):
#then just recursively call the funtion
# for both left and the righ tchild
else:
#append that into the answer list and recursively call
# the function again for their only child
def noSibling(root): #this is the main fnction
# code here
ans = [] #this is the answer array which we will return
add(root,ans) #this is the utility function which returns
# the required list
if ans==[]: # if every node has a sibling
ans = [-1] #[=1]
return ans