Transpose a grid · نقل مصفوفة
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] من كل صف.
Write transpose(grid) that turns rows into columns. grid is a list of rows, all the same length. [[1, 2, 3], [4, 5, 6]] becomes [[1, 4], [2, 5], [3, 6]]. · اكتب transpose(grid) يحول الصفوف إلى أعمدة. grid هي قائمة من الصفوف، جميعها بنفس الطول. [[1, 2, 3], [4, 5, 6]] تصبح [[1, 4], [2, 5], [3, 6]].
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.