zoukankan      html  css  js  c++  java
  • 【LEETCODE】48、867. Transpose Matrix

    package y2019.Algorithm.array;
    
    /**
     * @ProjectName: cutter-point
     * @Package: y2019.Algorithm.array
     * @ClassName: Transpose
     * @Author: xiaof
     * @Description: 867. Transpose Matrix
     *
     * Given a matrix A, return the transpose of A.
     * The transpose of a matrix is the matrix flipped over it's main diagonal, switching the row and column indices of the matrix.
     *
     * Input: [[1,2,3],[4,5,6],[7,8,9]]
     * Output: [[1,4,7],[2,5,8],[3,6,9]]
     *
     * Input: [[1,2,3],[4,5,6]]
     * Output: [[1,4],[2,5],[3,6]]
     *
     * @Date: 2019/7/4 15:44
     * @Version: 1.0
     */
    public class Transpose {
    
        public int[][] solution(int[][] A) {
    
            int[][] result = new int[A[0].length][A.length];
            for(int column = 0; column < A[0].length; ++column) {
                //
                for(int row = 0; row < A.length; ++row) {
                    result[column][row] = A[row][column];
                }
            }
    
            return result;
    
        }
    
    }
  • 相关阅读:
    Spring MVC之视图呈现
    Spring MVC之HandlerMap 初始化
    Spring MVC之DispatcherServlet请求处理
    合成模式
    缺省适配器
    适配器模式
    原始模型
    克隆 和 比较
    建造模式
    线段树
  • 原文地址:https://www.cnblogs.com/cutter-point/p/11135120.html
Copyright © 2011-2022 走看看