for(int i=0; i<board.length; i++){
    sum1=sum2=0;
    for(int j=0; j<board.length; j++){
        sum1 += board[i][j]; // 행의 합
        sum2 += board[j][i]; // 열의 합
    }
    answer = Math.max(answer, sum1);
    answer = Math.max(answer, sum2);
}

sum1=sum2=0;

// 대각선의 합 
for(int i=0; i<board.length; i++){
    sum1 += board[i][i];
    sum2 += board[i][board.length-i-1];
}

+ Recent posts