반응형
문제 : https://www.hackerrank.com/challenges/tree-huffman-decoding/problem?h_r=internal-search
해결 코드 :
import sys
sys.setrecursionlimit(2000)
def decodeHuff(root, s):
result = []
def _recursive(cur, root, binary):
#print(f'cur.data{cur.data} binary{binary}')
if cur.left==None and cur.right==None :
result.append(cur.data)
return _recursive(root, root, binary)
if not binary:
return
if binary[0] == '0':
cur = cur.left
else:
cur = cur.right
return _recursive(cur, root, binary[1:])
_recursive(root, root, s)
print(''.join(result))
return
반응형