Leetcode Note: Go - Convert 1d Array Into 2d Array

Convert 1D Array Into 2D Array - LeetCode
https://leetcode.com/problems/convert-1d-array-into-2d-array/

  • Go 言語で取り組んだメモ

回答

Two Golang Solution - Convert 1D Array Into 2D Array - LeetCode
https://leetcode.com/problems/convert-1d-array-into-2d-array/solutions/1499190/two-golang-solution/

func construct2DArray(original []int, m int, n int) [][]int {
    res := [][]int{}
    
    if len(original) == m * n {
        for i := 0; i < m; i++ {
            res = append(res, original[: n])
            original = original[n :]
        }
    }
    
    return res
}