Scroll indicator done
728x90

https://school.programmers.co.kr/learn/courses/30/lessons/12949

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr


조건
  • 행렬 arr1, arr2의 행과 열의 길이는 2 이상 100 이하입니다.
  • 행렬 arr1, arr2의 원소는 -10 이상 20 이하인 자연수입니다.
  • 곱할 수 있는 배열만 주어집니다.

3x2 → 2x2 → 3x2
3x3 → 3x3 → 3x3
row: 3
col: 2


package com.example.javaproject3.psstudy;

import java.util.Arrays;

public class Solution12949 {
    public int[][] solution(int[][] arr1, int[][] arr2) {
        int[][] answer = new int[arr1.length][arr2[0].length];

        for(int k=0; k<arr1.length; k++){
            for(int i=0; i<arr2[0].length; i++){
                for(int j=0; j<arr2.length; j++){
                    answer[k][i] += (arr1[k][j] * arr2[j][i]);
                }
            }
        }
        return answer;
    }

    public static void main(String[] args) {
        int[][] arr1 = {{2, 3, 2}, {4, 2, 4}, {3, 1, 4}};
        int[][] arr2 = {{5, 4, 3}, {2, 4, 1}, {3, 1, 1}};
        int[][] arr3 = {{1, 4}, {3, 2}, {4, 1}};
        int[][] arr4 = {{3, 3}, {3, 3}};
        Solution12949 solution12949 = new Solution12949();
        int[][] ans = solution12949.solution(arr3, arr4);
        System.out.println(Arrays.toString(ans[0]));
        System.out.println(Arrays.toString(ans[1]));
        System.out.println(Arrays.toString(ans[1]));
    }
}

728x90