Golang Leetcode 867. Transpose Matrix.go

2019-05-05 11:53:29 浏览数 (1)

版权声明:原创勿转 https://cloud.tencent.com/developer/article/1420470

思路

直接交换对应位置上的值

code

代码语言:javascript复制
func transpose(A [][]int) [][]int {
	m := len(A)
	n := len(A[0])
	ans := make([][]int, n)
	for k := range ans {
		ans[k] = make([]int, m)
	}
	for r := 0; r < m; r   {
		for c := 0; c < n; c   {
			ans[c][r] = A[r][c]
		}
	}
	return ans
}

0 人点赞