[JAVA 문제 풀이] 209. 특별한 이차원 배열

프로그래머스 (181833)
Stupefyee's avatar
Apr 18, 2025
[JAVA 문제 풀이] 209. 특별한 이차원 배열
notion image
 

내가 작성한 코드

class Solution { public int[][] solution(int n) { int[][] answer = new int[n][n]; for(int i = 0; i < n; i++) { answer[i][i] = 1; } return answer; } }
 

다른 사람의 코드

import java.util.stream.IntStream; class Solution { public int[][] solution(int n) { return IntStream.range(0, n).mapToObj(i -> IntStream.range(0, n).map(j -> j == i ? 1 : 0).toArray()).toArray(int[][]::new); } }
 
Share article

stupefyee