I am new to Java and have below code.
List<List<TreeNode>> dp = new ArrayList<List<TreeNode>>(N + 1);
System.out.println(dp.isEmpty());
for (int i = 0; i <= N; i++) {
dp.set(i, new ArrayList<TreeNode>());
}
dp.isEmpty() returns true; and I have Java.lang.IndexofBoundsException for line dp.set()...
I thought after new.. the dp already has N+1 entries, but it turned out wrong....dp is still empty..
so How can populate dp with N+1 arraylist