题解 | #蛇形矩阵#

蛇形矩阵

http://www.nowcoder.com/practice/649b210ef44446e3b1cd1be6fa4cab5e

let num = parseInt(readline());
let arr = [];
let len = arr.length;
while(num>len){
    let child=[]
    if(len===0){
        child=[1]
    }else{			
        child=[arr[len-1][0]+len]
    }	
    for(let i=len,j=0;i<num-1;i++,j++){
        child.push(child[j]+i+2)
    }
    len+=1
    arr.push(child)
}
arr.forEach(item=>{
    console.log(item.join(' '))
})
全部评论

相关推荐

牛客96763241...:杭电✌️也是打完招呼,没人回吗
点赞 评论 收藏
分享
09-22 15:45
门头沟学院 Java
谁给娃offer我给...:我也遇到了,我说只要我通过面试我就去,实际上我根本就不会去😁
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务