Tree: Huffman Decoding HackerRank Solution


Tree: Huffman Decoding HackerRank Solution
Source : https://www.hackerrank.com/challenges/tree-huffman-decoding



Source : https://www.hackerrank.com/challenges/tree-huffman-decoding


Solution


// Karthikalapati.blogspot.com
/*
class Node {
public int frequency; // the frequency of this tree
public char data;
public Node left, right;
}
*/
void decode(String str, Node root) {
Node n = root;
for (int i = 0; i < str.length(); i++) {
n = (str.charAt(i) == '0') ? n.left : n.right;
if (n.left == null && n.right == null) {
System.out.print(n.data);
n = root;
}
}
}

1 comment:

  1. Hi, extremely interesting article. My sister and I have been recently looking to find comprehensive info on this subject kind of stuff for a short time, but we didn’t until now. Do you think you can also make some youtube videos about this, I believe your website will be far more detailed in case you did. In any other case, oh well. I will be checking out on this website in the forseeable future. Email me to keep me up to date. granite countertops cleveland How long does PatPat take to deliver?

    ReplyDelete