Skip to content

Commit 70607d4

Browse files
authored
Merge pull request #1390 from AlgorithmWithGod/LiiNi-coder
[20251112] PGM / LV2 / 땅따먹기 / 이인희
2 parents 092245a + 9738462 commit 70607d4

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
```java
2+
import java.util.*;
3+
class Solution {
4+
int solution(int[][] land) {
5+
int n = land.length;
6+
for(int i=1; i<n; i++){
7+
land[i][0] += Math.max(Math.max(land[i-1][1], land[i-1][2]), land[i-1][3]);
8+
land[i][1] += Math.max(Math.max(land[i-1][0], land[i-1][2]), land[i-1][3]);
9+
land[i][2] += Math.max(Math.max(land[i-1][0], land[i-1][1]), land[i-1][3]);
10+
land[i][3] += Math.max(Math.max(land[i-1][0], land[i-1][1]), land[i-1][2]);
11+
}
12+
int last = n - 1;
13+
int answer = -1;
14+
for(int i = 0; i< 4; i++){
15+
if(answer <= land[last][i])
16+
answer = land[last][i];
17+
}
18+
return answer;
19+
}
20+
}
21+
22+
```

0 commit comments

Comments
 (0)