You are viewing a single comment's thread. Return to all comments →
I am trying the below solution but it says "wrong answer".
public static void topView(Node root) { if(root.left != null){ printLeft(root.left); } System.out.print(String.valueOf(root.data) + ' '); getLeftNode(root.left); System.out.print(String.valueOf(root.data) + ' '); Node rightNode = root.right; while(rightNode != null) { System.out.print(String.valueOf(rightNode.data) + ' '); rightNode = rightNode.right; } } public static void getLeftNode(Node leftNode) { if (leftNode != null) { getLeftNode(leftNode.left); System.err.println(String.valueOf(leftNode.data) + ' '); // System.out.print(String.valueOf(root.data) + ' '); } }
Can anyone please help me in this?
Seems like cookies are disabled on this browser, please enable them to open this website
Tree : Top View
You are viewing a single comment's thread. Return to all comments →
I am trying the below solution but it says "wrong answer".
Can anyone please help me in this?