Tree: Huffman Decoding

  • + 0 comments

    took some time to debug and understand it. The empty data is represented as string: chr(0) which is NUL in ascii.

    def decodeHuff(root, s):
        #Enter Your Code Here
        head = root
        
        for b in s:
            if b == '0':
                head = head.left
                if head.data != chr(0):
                    print(head.data, end='')
                    head = root
            else:
                head = head.right
                if head.data != chr(0):
                    print(head.data, end='')
                    head = root