Skip to content

Commit 4739b0d

Browse files
committed
867.转置矩阵,置换
1 parent 013954a commit 4739b0d

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

leetcode_Java/DoneTitle.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
714. 买卖股票的最佳时机含手续费
134134
718. 最长重复子数组
135135
739. 每日温度
136+
867. 转置矩阵
136137
901. 股票价格跨度
137138
1020. 飞地的数量
138139
1035. 不相交的线

leetcode_Java/DoneType.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
560. 和为 K 的子数组(前缀和,哈希表)
165165
581. 最短无序连续子数组(排序,双指针)
166166
704. 二分查找
167-
167+
867. 转置矩阵(置换)
168168

169169
八、字符串
170170
3. 无重复字符的最长子串(滑动窗口)

leetcode_Java/Solution0867.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// 867. 转置矩阵
2+
3+
4+
/*
5+
置换:创建新的矩阵,原矩阵值赋值到新矩阵行列索引交换的位置上
6+
*/
7+
class Solution {
8+
public int[][] transpose(int[][] matrix) {
9+
int m = matrix.length, n = matrix[0].length;
10+
int[][] res = new int[n][m];
11+
for (int i = 0; i < m; i++) {
12+
for (int j = 0; j < n; j++) {
13+
res[j][i] = matrix[i][j];
14+
}
15+
}
16+
return res;
17+
}
18+
}

0 commit comments

Comments
 (0)