Skip to content

Commit 8b7eb5f

Browse files
Add files via upload
1 parent ef44f97 commit 8b7eb5f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

NODES WITHOUT SIBLINGS.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
public class Solution {
2+
3+
public static void printNodesWithoutSibling(BinaryTreeNode<Integer> root) {
4+
//Your code goes here
5+
if (root==null)
6+
{
7+
return;
8+
}
9+
10+
if (root.left==null && root.right==null)
11+
{
12+
return;
13+
}
14+
15+
if (root.left==null)
16+
{
17+
System.out.print(root.right.data+" ");
18+
printNodesWithoutSibling(root.right);
19+
}
20+
else if (root.right==null)
21+
{
22+
System.out.print(root.left.data+" ");
23+
printNodesWithoutSibling(root.left);
24+
25+
}
26+
else
27+
{
28+
printNodesWithoutSibling(root.left);
29+
printNodesWithoutSibling(root.right);
30+
}
31+
}
32+
33+
}

0 commit comments

Comments
 (0)