Read List of note

From this question:

You are given a CSV file with 3 columns — all integers:


0 is the assumed root node with weight 0

which describes a tree-like structure — each line is a node, ‘parent’ refers to ‘id’ of another node.

Print out, for each node, the total weight of a subtree below this node (by convention, the weight of a subtree for node X includes the own weight of X).

You may assume that the input comes pre-parsed as a sequence of Node objects
(substitute the appropriate syntax for java/python/c++):

Node {
int id;
int parent;
int weight;
// … you can add other fields right here, if necessary

implement the following:
public void printSubTreeWeight(List<Node> nodes) {

……To be update


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s