상세 컨텐츠

본문 제목

땅따먹기 (연습문제)

프로그래머스 코딩테스트 풀이

by 발발개발 2022. 7. 29. 14:24

본문

원본 : https://school.programmers.co.kr/learn/courses/30/lessons/12913

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

풀이

class Solution {
    int solution(int[][] land) {
        for (int i = 1; i < land.length; i++) {
            for (int j = 0; j < 4; j++) {
                int max = 0;

                for (int k = 0; k < 4; k++) {
                    if (k != j) {
                        max = Math.max(max, land[i - 1][k]);
                    }
                }

                land[i][j] += max;
            }
        }

        int[] lastRow = land[land.length - 1];
        return Math.max(Math.max(lastRow[0], lastRow[1]), Math.max(lastRow[2], lastRow[3]));
    }
}

관련글 더보기

댓글 영역