Leetcode Complete Graph Traversal Algorithm