코딩테스트/프로그래머스 - LV 0

[프로그래머스] 특별한 이차원 배열 1

웅드 2024. 1. 31. 16:37

 

 

  • 풀이
#include <string>
#include <vector>

using namespace std;

vector<vector<int>> solution(int n) {
    vector<vector<int>> answer(n,vector<int>(n));
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i==j) answer[i][j]=1;
            else answer[i][j]=0;
        }
    }
    return answer;
}
반응형