You are viewing a single comment's thread. Return to all comments →
Java 8:
private int printLeaf(int stepNum, String s, Node node) { if (Objects.nonNull(node.left) && s.charAt(stepNum) == '0') stepNum = printLeaf(stepNum + 1, s, node.left); else if (Objects.nonNull(node.right) && s.charAt(stepNum) == '1') stepNum = printLeaf(stepNum + 1, s, node.right); System.out.print(node.data); return stepNum; } void decode(String s, Node root) { int cur = 0; while (cur < s.length()) cur = printLeaf(cur, s, root); }
Not sure what am I missing, it prints all the correct valued in the output, but shows "Wrong answer".
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:
Not sure what am I missing, it prints all the correct valued in the output, but shows "Wrong answer".