We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
void decode(String s, Node root) {
Node node = root;
for(int i=0; i<s.length(); i++){
char c = s.charAt(i);
if(c == '1') node = node.right; //Move Right if char is 1
else node = node.left; // Move left if char is 0
//If leaf node is reached then print the data and move back to root
if(node.right== null && node.left== null){
System.out.print(node.data);
node = root;
}
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tree: Huffman Decoding
You are viewing a single comment's thread. Return to all comments →
Java 8 - Easy to Understand