public List<Integer> spiralOrder(int[][] matrix) {
int l = 0;
int r = matrix[0].length - 1;
int u = 0;
int d = matrix.length - 1;
List<Integer> list=new ArrayList<>();
while(l<=r&&u<=d){
for(int i=l;i<=r;i++){
list.add(matrix[u][i]);
}
u++;
for(int i=u;i<=d;i++){
list.add(matrix[i][r]);
}
r--;
for (int i = r; i >= l && u <= d; i--) {
list.add(matrix[d][i]);
}
d--;
for (int i = d; i >= u && l <= r; i--) {
list.add(matrix[i][l]);
}
l++;
}
return list;
}
标签:matrix,螺旋,int,List,矩阵,lc54,length,&&
From: https://www.cnblogs.com/doudou666/p/18145869