Skip to content

Commit

Permalink
variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Nivedita967 committed Dec 18, 2020
1 parent eced142 commit 54bfe5f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Trees/Tree-Huffman Decoding/solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ class Node
void decode(String s, Node root) {

// StringBuilder over String because StringBuilder is mutable
StringBuilder sb = new StringBuilder();
StringBuilder res_str = new StringBuilder();
Node node = root;
// traverse each character of string
for (int i = 0; i < s.length(); i++) {
// if character= 1, move to right otherwise left
node = s.charAt(i) == '1' ? node.right : node.left;
// if it is a leaf node append character to our string result
if (node.left == null && node.right == null) { // leaf nodes
sb.append(node.data);
res_str.append(node.data);
node = root;
}
}
// print resultant string
System.out.print(sb);
System.out.print(res_str);

}

Expand Down

0 comments on commit 54bfe5f

Please sign in to comment.