Tree: Huffman Decoding

  • + 0 comments

    def decodeHuff(root, s): #Enter Your Code Here

    code = ''
    start = 0 
    end = 0
    n = len(s)
    node = root
    #print(node.left.data)
    while end < n:
        # print(code)
        # print(end)
    
        if node.left or node.right:
            if s[end] == '0':
                node = node.left
            else:#=1
                node = node.right
            end+=1
        else:#stop letter
            # print('stop letter')
            code = code + node.data
            node = root
    code = code + node.data#Last potential letter excluded from loop
    print (code)