Skip to content

Instantly share code, notes, and snippets.

@keyvanakbary
Created February 23, 2017 22:40
Show Gist options
  • Save keyvanakbary/3ecbf221a0243d36fbbcb16549731319 to your computer and use it in GitHub Desktop.
Save keyvanakbary/3ecbf221a0243d36fbbcb16549731319 to your computer and use it in GitHub Desktop.
public class Solution {
public void traverse(TreeNode root) {
Queue<TreeNode> nodes = new ArrayList();
nodes.add(root);
while (!nodes.isEmpty()) {
TreeNode node = nodes.remove();
System.out.println(node.val);
if (node.left != null) queue.add(node.left);
if (node.right != null) queue.add(node.right);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment