Level 1 - 행렬의 덧셈
행렬의 덧셈은 행과 열의 크기가 같은 두 행렬의 같은 행, 같은 열의 값을 서로 더한 결과가 됩니다. 2개의 행렬을 입력받는 sumMatrix 함수를 완성하여 행렬 덧셈의 결과를 반환해 주세요.예를 들어 2x2 행렬인 A = ((1, 2), (2, 3)), B = ((3, 4), (5, 6)) 가 주어지면, 같은 2x2 행렬인 ((4, 6), (7, 9))를 반환하면 됩니다.(어떠한 행렬에도 대응하는 함수를 완성해주세요.) 풀이class SumMatrix {int[][] sumMatrix(int[][] A, int[][] B) {int[][] answer = new int[A.length][A[0].length]; for (int i = 0; i < A.length; i++) { for (int j = ..
더보기
Common Elements in Two Sorted Arrays (Java)
Common Elements in Two Sorted Arrays (Java)Write a function that returns the common elements (as an array) between two sorted arrays of integers (ascending order).Example: The common elements between [1, 3, 4, 6, 7, 9] and [1, 2, 4, 5, 9, 10] are [1, 4, 9]. 풀이ascending order임으로 중복된 숫자는 안들어감map 에 담아서 중복되는 게 있으면 list에 담아두고 이걸 나중에 array 변환 (list는 resizable하니까) import java.util.ArrayList;import java..
더보기