螺旋矩阵
let luoxuan =(matrix)=>{
if(matrix.length==0) return []
let arr1=[]
let top=0;
let bottom=matrix.length-1;
let left=0;
let right=matrix[0].length-1;
while(top<=bottom&&left<=right){
for(let i=left;i<=right;i++){
arr1.push(matrix[top][i])
}
for(let i=top+1;i<=bottom;i++){
arr1.push(matrix[i][right])
}
for(let i=right-1;i>=left&&top!=bottom;i--){
arr1.push(matrix[bottom][i])
}
for(let i=bottom-1;i>top&&left!==right;i--){
arr1.push(matrix[i][left])
}
top++;
bottom--;
left++;
right--;
}
return arr1
}
let arr=[[1,2,3,4],[5,6,7,8],[9,10,11,12]]
console.log(luoxuan(arr));