Skip to content

Transpose a grid · ⁨网格转置⁩

English

Transpose a grid

Swap the rows and columns of a grid, as if you reflected a table across its diagonal.

grid[r][c] is the item in row r and column c. The new grid has one row for each column of the old one, so loop over the column numbers first, and inside that loop collect row[col] from every row.

中文

网格转置

交换网格的行和列,就像沿着对角线翻转一张表格。

grid[r][c] 是第 r 行、第 c 列的元素。新网格的每一行对应旧网格的每一列,所以先遍历列号,再在这个循环里从每一行取出 row[col]。

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩