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.
21 lines
391 B
21 lines
391 B
8 months ago
|
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
|
||
|
}
|