Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
513 B
1
Indexable
Never
#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