2017-03-05 00:26:42 -06:00
|
|
|
// Author: Rodney Shaghoulian
|
2018-07-27 16:45:56 -07:00
|
|
|
// Github: github.com/RodneyShag
|
|
|
|
|
// HackerRank: hackerrank.com/RodneyShag
|
2017-03-05 00:26:42 -06:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
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++) {
|
2017-04-05 18:42:35 -05:00
|
|
|
n = (str.charAt(i) == '0') ? n.left : n.right;
|
2017-03-05 00:26:42 -06:00
|
|
|
if (n.left == null && n.right == null) {
|
|
|
|
|
System.out.print(n.data);
|
|
|
|
|
n = root;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|