zoukankan      html  css  js  c++  java
  • Leetcode 867转置矩阵

    题目定义:

    给你一个二维整数数组 matrix, 返回 matrix 的 转置矩阵 。
    
    矩阵的 转置 是指将矩阵的主对角线翻转,交换矩阵的行索引与列索引。
    
    
    

    img

    示例 1:
    输入:matrix = [[1,2,3],[4,5,6],[7,8,9]]
    输出:[[1,4,7],[2,5,8],[3,6,9]]
        
    示例 2:
    输入:matrix = [[1,2,3],[4,5,6]]
    输出:[[1,4],[2,5],[3,6]]
    

    方式一:

    class Solution {
        public int[][] transpose(int[][] matrix) {
            int[][] ans = new int[matrix[0].length][matrix.length];
            for(int i = 0; i < matrix.length; i++){
                for(int j = 0; j <matrix[0].length; j++){
                    ans[j][i] = matrix[i][j];
                }
            }
            return ans;
        }
    }
    
  • 相关阅读:
    spring框架
    自己来到这个世界的天数
    迭代器
    String
    mybatis-plus条件参数
    Linux常用命令
    web.xml
    log4j.properties
    springmvc.xml
    applicationContext.xml
  • 原文地址:https://www.cnblogs.com/CodingXu-jie/p/14446331.html
Copyright © 2011-2022 走看看