题目:
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.
For example, given the following matrix:
[
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ]
]
You should return [1,2,3,6,9,8,7,4,5].
解决方案:
public ArrayList<Integer> spiralOrder(int[][] matrix){ArrayList<Integer> result=new ArrayList<Integer>();if(matrix==null||matrix.length==0)return result;int m=matrix.length;int n=matrix[0].length;int x=0;int y=0;while(m&......
阅读全文