Untitled
unknown
plain_text
3 years ago
507 B
20
Indexable
In order to generate a Spiral Order Matrix with given integer A.
We need to declare one ArrayList and Initialize it.
I have done it like below.
ArrayList<ArrayList<Integer>> spiralMatrix = new ArrayList<ArrayList<Integer>>();
for(int i=0;i<A;i++) {
spiralMatrix.add(new ArrayList<Integer>());
for(int j=0;j<A;j++) {
spiralMatrix.get(i).add(0);
}
}
Is there any alternative way? because we are wasting O(N^2) for Initializing
Editor is loading...