public void toArray(TreeNode node, List<Integer> list) {
        if (node != null) {
            if (node.left != null)
                toArray(node.left, list);
            list.add(node.val);
            if (node.right != null)
                toArray(node.right, list);
        }
    }