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 ecc9320

Browse files
🐱(array): 867. 转置矩阵
1 parent 6af2984 commit ecc9320

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2986,6 +2986,28 @@ class Solution:
29862986
return A
29872987
```
29882988

2989+
## 867. 转置矩阵
2990+
2991+
[原题链接](https://leetcode-cn.com/problems/transpose-matrix/)
2992+
2993+
### 思路
2994+
2995+
模拟矩阵转置过程,即二维数组下标参数兑换:`ans[j][i] = matrix[i][j]`
2996+
2997+
```python
2998+
class Solution:
2999+
def transpose(self, matrix: List[List[int]]) -> List[List[int]]:
3000+
m = len(matrix)
3001+
n = len(matrix[0])
3002+
ans = [[0 for _ in range(m)] for _ in range(n)]
3003+
3004+
for i in range(m):
3005+
for j in range(n):
3006+
ans[j][i] = matrix[i][j]
3007+
3008+
return ans
3009+
```
3010+
29893011
## 914. 卡牌分组
29903012

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

0 commit comments

Comments
(0)

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