일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- 저요오드식
- 수술
- 코틀린 인 액션
- 백준알고리즘
- java
- 프로그래머스
- MYSQL
- 임파선전이
- firebase
- 입원
- Android
- 방사성 동위원소 치료
- 개발책
- 방사성동위원소치료
- kotlin In Action
- 알고리즘
- 갑상선암
- 코틀린
- kotlin
- Android Compose
- Compose
- android auto
- 자바
- 정렬 알고리즘
- 카페
- 개발독서
- 림프절전이
- leetcode
- 동위원소치료
- 맛집
Archives
- Today
- Total
새우버거의 개발 블로그
[JAVA] 프로그래머스 Lv.2 : 땅따먹기 본문
예제:
land | answer |
[[1,2,3,5],[5,6,7,8],[4,3,2,1]] | 16 |
제한 조건:
- 행의 개수 N : 100,000 이하의 자연수
- 열의 개수는 4개이고, 땅(land)은 2차원 배열로 주어집니다.
- 점수 : 100 이하의 자연수
Solution #1
import java.util.Arrays;
class Solution {
int solution(int[][] land) {
int answer = 0;
for (int i = 0; i < land.length - 1; i++) {
land[i + 1][0] += Math.max(Math.max(land[i][1], land[i][2]), land[i][3]);
land[i + 1][1] += Math.max(Math.max(land[i][0], land[i][2]), land[i][3]);
land[i + 1][2] += Math.max(Math.max(land[i][0], land[i][1]), land[i][3]);
land[i + 1][3] += Math.max(Math.max(land[i][0], land[i][1]), land[i][2]);
}
for (int i = 0; i < 4; i++) {
if (land[land.length - 1][i] >= answer) {
answer = land[land.length - 1][i];
}
}
return answer;
}
}
Result #1
More Algorithm!
👇👇
github.com/ggujangi/ggu.programmers
ggujangi/ggu.programmers
프로그래머스 알고리즘, JAVA. Contribute to ggujangi/ggu.programmers development by creating an account on GitHub.
github.com
출처 : 프로그래머스
'프로그래머스 - JAVA > Level 2' 카테고리의 다른 글
[JAVA] 프로그래머스 Lv.2 : 짝지어 제거하기 (0) | 2021.06.23 |
---|---|
[JAVA] 프로그래머스 Lv.2 : 올바른 괄호 (0) | 2021.06.23 |
[JAVA] 프로그래머스 Lv.2 : 숫자의 표현 (0) | 2021.06.09 |
[JAVA] 프로그래머스 Lv.2 : 최댓값과 최솟값 (0) | 2021.06.09 |
[JAVA] 프로그래머스 Lv.2 : 피보나치 수 (0) | 2021.06.09 |