keon / algorithms

Minimal examples of data structures and algorithms in Python
MIT License
23.77k stars 4.59k forks source link

Structure testing function num_decodings.py #866

Open Eurus44 opened 2 years ago

aminulqrshah commented 2 years ago

def binary_tree_paths(root):     res = []     if root is None:         return res     dfs(res, root, str(root.val))     return res

def dfs(res, root, cur):     if root.left is None and root.right is None:         res.append(cur)     if root.left:         dfs(res, root.left, cur+'->'+str(root.left.val))     if root.right:         dfs(res, root.right, cur+'->'+str(root.right.val))@