Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3e4916b

Browse files
🐱(array): 867. 转置矩阵
补充 Go 语言解法
1 parent ecc9320 commit 3e4916b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

‎docs/data-structure/array/README.md‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2994,6 +2994,10 @@ class Solution:
29942994

29952995
模拟矩阵转置过程,即二维数组下标参数兑换:`ans[j][i] = matrix[i][j]`
29962996

2997+
<!-- tabs:start -->
2998+
2999+
#### **Python**
3000+
29973001
```python
29983002
class Solution:
29993003
def transpose(self, matrix: List[List[int]]) -> List[List[int]]:
@@ -3008,6 +3012,34 @@ class Solution:
30083012
return ans
30093013
```
30103014

3015+
#### **Go**
3016+
3017+
```go
3018+
func transpose(matrix [][]int) [][]int {
3019+
m := len(matrix)
3020+
n := len(matrix[0])
3021+
ans := make([][]int, n)
3022+
// 初始化
3023+
for i := range ans {
3024+
ans[i] = make([]int, m)
3025+
for j := range ans[i] {
3026+
ans[i][j] = 0
3027+
}
3028+
}
3029+
3030+
// 赋值
3031+
for i, row:= range matrix {
3032+
for j, v := range row {
3033+
ans[j][i] = v
3034+
}
3035+
}
3036+
3037+
return ans
3038+
}
3039+
```
3040+
3041+
<!-- tabs:end -->
3042+
30113043
## 914. 卡牌分组
30123044

30133045
[原题链接](https://leetcode-cn.com/problems/x-of-a-kind-in-a-deck-of-cards/)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /