You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
lavos/cap3/work4.go

20 lines
391 B

package cap3
func Work4(n int) [][]int {
matrix := make([][]int, n)
// 逐行长度递减的上三角矩阵
for i := range matrix {
matrix[i] = make([]int, n-i)
}
// 沿右上方向斜向上填充
num := 1
for i := 0; i < n; i++ {
for j := 0; j <= i; j++ {
matrix[i-j][j] = num
num++
}
}
return matrix
}