You are viewing a single comment's thread. Return to all comments →
All the java solutions I see here are overcomplicated. Here's a simple solution without recursion or additional datastructures:
void decode(String s, Node root) { Node n = root; for (int i=0; i < s.length(); i++) { if (s.charAt(i) == '0') { n = n.left; } else { n = n.right; } if (n.data > 0) { System.out.print(n.data); n = root; } } }
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 →
All the java solutions I see here are overcomplicated. Here's a simple solution without recursion or additional datastructures: