*
* @param matrix int整型二维数组
* @return int整型一维数组
*/
function spiralOrder( matrix ) {
// write code here
let res = [];
if(matrix.length === 0) return res;
let l = 0,r = matrix[0].length - 1;
let t = 0,b = matrix.length - 1;
while(1){
for(let i = l;i <= r;i++){
res.push(matrix[t][i]);
}
if(++t > b) break;
for(let i = t;i <= b;i++){
res.push(matrix[i][r]);
}
if(--r < l) break;
for(let i = r;i >= l;i--){
res.push(matrix[b][i]);
}
if(--b < t) break;
for(let i = b;i >= t;i--){
res.push(matrix[i][l]);
}
if(++l > r) break;
}
return res;
}
module.exports = {
spiralOrder : spiralOrder
};