Tree: Huffman Decoding

  • + 0 comments

    simple python solution

    def decodeHuff(root, s):
        node = root
        ans = ""
        for i in s:
            if node is None:
                return
            if i == "1":
                node = node.right
            elif i == "0":
                node = node.left
            if node.left is None and node.right is None:
                ans += node.data
                node = root
        print(ans)