题解 | #蛇形矩阵#
蛇形矩阵
http://www.nowcoder.com/practice/649b210ef44446e3b1cd1be6fa4cab5e
const line = parseInt(readline()) const arr = [] let current = 0; for( let step = 0; step < line; step++ ) { for( let i = 0; i <= step; i++ ) { const j = step - i if( !arr[j] ) { arr[j] = [] } current++ arr[j][i] = current } } arr.forEach( item => { const str = item.join(" ") console.log( str ) })