标签:col for arraylist color while new nbsp 螺旋矩阵 solution
螺旋矩阵
class Solution { public List<Integer> spiralOrder(int[][] matrix) { List<Integer> list = new ArrayList<>(); int xlen = matrix.length; if(xlen==0||matrix[0].length==0){ return list; } int ylen = matrix[0].length; int i = 0; int j = ylen-1; int m = xlen-1; int n = 0; while(i<=m&&n<=j){ for(int k=n;k<=j;++k){ list.add(matrix[i][k]); } ++i; if(n<=j){ for(int k=i;k<=m;++k){ list.add(matrix[k][j]); } } --j; if(i<=m){ for(int k=j;k>=n;--k){ list.add(matrix[m][k]); } } --m; if(n<=j){ for(int k=m;k>=i;--k){ list.add(matrix[k][n]); } } ++n; } return list; } }
标签:col for arraylist color while new nbsp 螺旋矩阵 solution
原文地址:https://www.cnblogs.com/erdanyang/p/11240630.html