Guest User

Untitled

a guest
Dec 13th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. void decode(String S ,Node root)
  2. {
  3. StringBuilder sb = new StringBuilder();
  4. Node head = root;
  5. for(int i = 0; i < S.length(); i++){
  6.  
  7. char c = S.charAt(i);
  8.  
  9. if(c == '1'){
  10. //System.out.println("Saw one moving right");
  11. root = root.right;
  12. } else {
  13. //System.out.println("Saw zero moving left");
  14. root = root.left;
  15. }
  16. if(root.left == null && root.right == null){
  17. //System.out.println("Saw leaf node printing char");
  18. sb.append(root.data);
  19. root = head;
  20. }
  21.  
  22.  
  23. }
  24.  
  25. System.out.println(sb.toString());
  26.  
  27. }
Add Comment
Please, Sign In to add comment