cholic-1025
Results
1
comments of
cholic-1025
还有更简洁的解法,先定义好前进的方向,“右-下-左-上”,当前进方向上不能继续时(超出数组或者已经被填充),就换到下一个方向继续前进。只需要一个循环和一个if就能完成 ``` var generateMatrix = function(n) { let x = 0, y = 0, current = 1, last = n * n; const xDirections = [1, 0, -1, 0]; //...