QuestionGiven anm x nmatrix, returnall elements of thematrixin spiral order.Example:Input: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
Output: [1,2,3,4,8,12,11,10,9,5,6,7]Constraints:m == matrix.lengthn == matrix[i].length1 <= m, n <= 10-100 <= matrix[i][j] <= 100AlgorithmNo trick question, implement step by step according to intuition.CodeclassSolution{publicListspiralOrder(int[][]matrix) {Listres=newArrayList();if(matrix==null||matrix.length==0||matrix[0]==null||matrix[0].length==0) {returnres;}intbottom=matrix.length-1;intright=matrix[0].length-1;intleft=0;inttop=0;introw=left;intcol=top;wh
...
继续阅读
(15)