웅재의 코딩세상

[프로그래머스] 이차원 배열 대각선 순회하기 본문

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

[프로그래머스] 이차원 배열 대각선 순회하기

웅드 2024. 2. 1. 21:25

 

 

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

using namespace std;

int solution(vector<vector<int>> board, int k) {
    int answer = 0;
    for(int i=0; i<board.size(); i++){
        for(int j=0; j<board[i].size(); j++){
            if(i+j <= k) answer += board[i][j];
        }
    }
    return answer;
}
반응형