Created
February 23, 2017 22:40
-
-
Save keyvanakbary/3ecbf221a0243d36fbbcb16549731319 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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