public List<List<Integer>> levelOrder(TreeNode root) {
        ArrayList<List<Integer>> result = new ArrayList<List<Integer>>();

        if (root == null) {
            return result;
        }

        Queue<TreeNode> queue = new LinkedList<TreeNode>();
        Set<TreeNode> V = new HashSet<TreeNode>();

        V.add(root);
        queue.add(root);



        while (!queue.isEmpty()) {
            ArrayList<Integer> numList = new ArrayList<Integer>();
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                TreeNode tmp = queue.remove();
                numList.add(tmp.val);
                ArrayList<TreeNode> children = new ArrayList<TreeNode>();
                if (tmp.left != null) {
                    children.add(tmp.left);
                }
                if (tmp.right != null) {
                    children.add(tmp.right);
                }
                for (TreeNode tmpNode : children) {
                    if (!V.contains(tmpNode)) {
                        V.add(tmpNode);
                        queue.add(tmpNode);
                    }
                }
            }
            result.add(numList);
        }
        return result;
    }