I have a function which creates a 2d slice, one row and three columns
func threeSum(nums []int) [][]int {
result := make([][]int, 1)
result[0] = []int{1, 2, 3}
return result
}
What if I want to dynamically add a row?
If result
was just a normal slice I would just append to the end of the slice, however with the 2d array it seems I have to manually do a lot of things, is there an easier way?
EDIT: My way of doing it would be, if I need to add a new row:
result = append(result, []int{4, 2, 3})
Which in hindsight isn't actually bad :) If anyone has an opinion I'll be happy to accept.