Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void decode(String S ,Node root)
- {
- StringBuilder sb = new StringBuilder();
- Node head = root;
- for(int i = 0; i < S.length(); i++){
- char c = S.charAt(i);
- if(c == '1'){
- //System.out.println("Saw one moving right");
- root = root.right;
- } else {
- //System.out.println("Saw zero moving left");
- root = root.left;
- }
- if(root.left == null && root.right == null){
- //System.out.println("Saw leaf node printing char");
- sb.append(root.data);
- root = head;
- }
- }
- System.out.println(sb.toString());
- }
Add Comment
Please, Sign In to add comment