Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Traditional way to recurse in every direction
- if node in trie.children:
- search(board, r+1, c, node, res)
- search(board, r-1, c, node, res)
- search(board, r, c+1, node, res)
- search(board, r, c-1, node, res)
- # Alternate way
- directions = [(0,1), (0,-1), (1,0), (-1,0)]
- if node in trie.children:
- for i, j in directions:
- search(board, r+i, c+j, child, res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement