Tree: Huffman Decoding

Sort by

recency

|

533 Discussions

|

  • + 0 comments

    Security is essential for my industry, and asp.net development outsourcing provide the peace of mind I need. I work with sensitive information daily, and knowing my applications are secure has been invaluable. It’s a relief to have a platform that takes data protection so seriously.

  • + 0 comments

    There is a bug, NULL (None) is represented by chr(0)

    def decodeHuff(root, s):
        i = 0
        node = root
        res = ""
        while i < len(s):
            while node.data == chr(0):
                if s[i] == '0':
                    assert node.left
                    node = node.left
                else:
                    assert node.right
                    node = node.right
                i += 1
            res += node.data
            node = root
        print(res)
    
  • + 0 comments

    U have left the meeting m

  • + 0 comments
    def decodeHuff(root, s):
    	#Enter Your Code Here
        string = ""
        cur = root
        for si in s:
            if si == '0':
                cur = cur.left
            elif si == '1':
                cur = cur.right
            if cur.left is None and cur.right is None:
                string += cur.data
                cur = root
                
        print(string)
    
  • + 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