mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 08:27:30 +08:00
13 lines
232 B
Go
13 lines
232 B
Go
package leetcode
|
|
|
|
func construct2DArray(original []int, m int, n int) [][]int {
|
|
if m*n != len(original) {
|
|
return [][]int{}
|
|
}
|
|
res := make([][]int, m)
|
|
for i := 0; i < m; i++ {
|
|
res[i] = original[n*i : n*(i+1)]
|
|
}
|
|
return res
|
|
}
|