1. <small id='oCYOn'></small><noframes id='oCYOn'>

        <bdo id='oCYOn'></bdo><ul id='oCYOn'></ul>

    2. <tfoot id='oCYOn'></tfoot>
      1. <i id='oCYOn'><tr id='oCYOn'><dt id='oCYOn'><q id='oCYOn'><span id='oCYOn'><b id='oCYOn'><form id='oCYOn'><ins id='oCYOn'></ins><ul id='oCYOn'></ul><sub id='oCYOn'></sub></form><legend id='oCYOn'></legend><bdo id='oCYOn'><pre id='oCYOn'><center id='oCYOn'></center></pre></bdo></b><th id='oCYOn'></th></span></q></dt></tr></i><div id='oCYOn'><tfoot id='oCYOn'></tfoot><dl id='oCYOn'><fieldset id='oCYOn'></fieldset></dl></div>
        <legend id='oCYOn'><style id='oCYOn'><dir id='oCYOn'><q id='oCYOn'></q></dir></style></legend>
      2. 向右旋转二维矩阵

        时间:2023-09-25

        <tfoot id='DwCZ5'></tfoot>

          <small id='DwCZ5'></small><noframes id='DwCZ5'>

          <i id='DwCZ5'><tr id='DwCZ5'><dt id='DwCZ5'><q id='DwCZ5'><span id='DwCZ5'><b id='DwCZ5'><form id='DwCZ5'><ins id='DwCZ5'></ins><ul id='DwCZ5'></ul><sub id='DwCZ5'></sub></form><legend id='DwCZ5'></legend><bdo id='DwCZ5'><pre id='DwCZ5'><center id='DwCZ5'></center></pre></bdo></b><th id='DwCZ5'></th></span></q></dt></tr></i><div id='DwCZ5'><tfoot id='DwCZ5'></tfoot><dl id='DwCZ5'><fieldset id='DwCZ5'></fieldset></dl></div>

            <legend id='DwCZ5'><style id='DwCZ5'><dir id='DwCZ5'><q id='DwCZ5'></q></dir></style></legend>

                <bdo id='DwCZ5'></bdo><ul id='DwCZ5'></ul>

                  <tbody id='DwCZ5'></tbody>
                1. 本文介绍了向右旋转二维矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想要一个 2d 矩阵向右旋转,它编译得很好,但是当我尝试运行时,它说 数组索引超出范围异常.例如,我希望 {{10,20,30},{40,50,60}} 旋转成 {{40,10},{50,20},{60,30}}:

                  I want a 2d matrix to rotate to the right, it compiles fine but when I try to the run it says that the array index is out of bounds exception. For example, I want {{10,20,30},{40,50,60}} to rotate into {{40,10},{50,20},{60,30}}:

                  public static int[][] rotate(int[][] m) {
                      int[][] rotateM = new int[m[0].length][m.length];
                      for (int i = 0; i < m.length; i++) {
                          for (int j = 0; j < m[0].length; j++) {
                              rotateM[i][j] = m[j][m.length - i - 1];
                          }
                      }
                      return rotateM;
                  }
                  

                  public static void main(String[] args) {
                      int[][] m = {
                              {10, 20, 30},
                              {40, 50, 60}};
                      System.out.println(Arrays.toString(rotate(m)));
                  }
                  

                  推荐答案

                  这是一个工作示例:

                  private int[][] rotateMatrix(int[][] matrix) {
                      int backupH = h;
                      int backupW = w;
                      w = backupH;
                      h = backupW;
                      int[][] ret = new int[h][w];
                      for (int i = 0; i < h; ++i) {
                          for (int j = 0; j < w; ++j) {
                              ret[i][j] = matrix[w - j - 1][i];
                          }
                      }
                      return ret;
                  }
                  

                  我使用此代码在俄罗斯方块中旋转我的积木.此代码顺时针旋转矩阵.

                  I used this code to rotate my bricks in Tetris. This code rotates the matrix clockwise.

                  这篇关于向右旋转二维矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Java:通过指定的度数值围绕另一个旋转点 下一篇:用于 ASP 经典的 base64 图像解码器

                  相关文章

                  <legend id='27RUi'><style id='27RUi'><dir id='27RUi'><q id='27RUi'></q></dir></style></legend>

                  1. <i id='27RUi'><tr id='27RUi'><dt id='27RUi'><q id='27RUi'><span id='27RUi'><b id='27RUi'><form id='27RUi'><ins id='27RUi'></ins><ul id='27RUi'></ul><sub id='27RUi'></sub></form><legend id='27RUi'></legend><bdo id='27RUi'><pre id='27RUi'><center id='27RUi'></center></pre></bdo></b><th id='27RUi'></th></span></q></dt></tr></i><div id='27RUi'><tfoot id='27RUi'></tfoot><dl id='27RUi'><fieldset id='27RUi'></fieldset></dl></div>

                    <small id='27RUi'></small><noframes id='27RUi'>

                    • <bdo id='27RUi'></bdo><ul id='27RUi'></ul>
                    <tfoot id='27RUi'></tfoot>