Home Article Practice 罗璇数组

罗璇数组

2020-10-05 09:03  views:416  source:小键人290027    

var spiralOrder = function(matrix) { var res=[] var i=0 var j=0 var n=matrix.length-1
if(n<0) return [] var m=matrix[0].length-1 var turn=m==0?'d':'r' var boundl=0 var
boundr=m var boundu=0 var boundd=n for(var a=0;a<(m+1)*(n+1);a++){ res.push(matrix[i
][j]) if(turn=='r'){ j++ if(j==boundr){ boundu++ turn='d'
} }else if(turn=='d'){ i++ if(i==boundd){ boundr-- turn='l'
} }else if(turn=='l'){ j-- if(j==boundl){ boundd-- turn='u'
} }else if(turn=='u'){ i-- if(i==boundu){ boundl++ turn='r'
} } } return res};



Disclaimer: The above articles are added by users themselves and are only for typing and communication purposes. They do not represent the views of this website, and this website does not assume any legal responsibility. This statement is hereby made! If there is any infringement of your rights, please contact us promptly to delete it.

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)