add: 220602 [cpp]
This commit is contained in:
parent
61780faad2
commit
7c522bb588
|
|
@ -0,0 +1,19 @@
|
|||
#include <vector>
|
||||
|
||||
/**
|
||||
* 867. Transpose Matrix
|
||||
* Given a 2D integer array matrix, return the transpose of matrix.
|
||||
* The transpose of a matrix is the matrix flipped over its main diagonal, switching the matrix's row and column indices.
|
||||
*/
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
static std::vector<std::vector<int>> transpose(std::vector<std::vector<int>>& matrix) {
|
||||
const int m = matrix.size(), n = matrix.front().size();
|
||||
std::vector<std::vector<int>> ret(n, std::vector<int>(m));
|
||||
for (int i = 0; i < m; ++i)
|
||||
for (int j = 0; j < n; ++j)
|
||||
ret[j][i] = matrix[i][j];
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
|
@ -3,4 +3,4 @@ PROJECT(2206)
|
|||
|
||||
SET(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
ADD_EXECUTABLE(2206 220601-CN.cpp)
|
||||
ADD_EXECUTABLE(2206 220602.cpp)
|
||||
|
|
|
|||
Loading…
Reference in New Issue