Tree Basics and some Swift helpers for leetcode
I do leetcoding every once a while, but keep forgetting some tree basics. This post here it to help with that. Node vs Side π‘ This was a very subtle yet βAhaβ moment for me. When youβre traversing down a tree using dfs, while you can do things like: let leftNode = process(node.left) let rightNode = process(node.right) it might be better to see at as: let leftSide = process(node.left) let rightSide = process(node.right) Mentally for me this was a big shift in how I see it. DFS is iteratively / recursively against a path, much like how you iterate against items within an array. At each iteration of the path, you just process a single node within the path. Decide to then further continue or stop. ...