@@ -0,0 +1,1017 @@
+package leetcode.binary_tree_preorder_traversal;%0A%0Aimport java.util.ArrayList;%0A%0Aimport common.TreeNode;%0A%0Apublic class Solution %7B%0A    public ArrayList%3CInteger%3E preorderTraversal(TreeNode root) %7B%0A    %09ArrayList%3CInteger%3E ans = new ArrayList%3CInteger%3E();%0A    %09if(root == null) return ans;%0A    %09ArrayList%3CTreeNode%3E stack = new ArrayList%3CTreeNode%3E();%0A    %09stack.add(root);%0A    %09while(stack.size() %3E 0)%7B%0A    %09%09TreeNode cur = stack.remove(stack.size() - 1);%0A    %09%09ans.add(cur.val);%0A    %09%09if(cur.right != null)%7B%0A    %09%09%09stack.add(cur.right);%0A    %09%09%7D%0A    %09%09if(cur.left != null)%7B%0A    %09%09%09stack.add(cur.left);%0A    %09%09%7D%0A    %09%7D%0A    %09return ans;%0A    %7D%0A    %0A    public static void main(String%5B%5D args)%7B%0A    %09TreeNode t1 = new TreeNode(1);%0A    %09TreeNode t2 = new TreeNode(2);%0A    %09TreeNode t3 = new TreeNode(3);%0A    %09TreeNode t4 = new TreeNode(4);%0A    %09t1.left = t2;%0A    %09t2.left = t3;%0A    %09t2.right = t4;%0A    %09for(int x : new Solution().preorderTraversal(t1))%7B%0A    %09%09System.err.print(x + %22-%3E%22);%0A    %09%7D%0A    %09System.err.println(%22%22);%0A    %7D%0A%7D%0A

Add java solution for 144. Binary Tree Preorder Traversal