Skip to content

Commit 99cb13f

Browse files
authored
Merge pull request #1177 from AlgorithmWithGod/ksinji
[20251020] PGM / LV2 / 땅따먹기 / 강신지
2 parents 58158a4 + 408c446 commit 99cb13f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
```java
2+
class Solution {
3+
public int solution(int[][] land) {
4+
int n = land.length;
5+
int a = land[0][0], b = land[0][1], c = land[0][2], d = land[0][3];
6+
7+
for (int i = 1; i < n; i++) {
8+
int na = land[i][0] + Math.max(Math.max(b, c), d);
9+
int nb = land[i][1] + Math.max(Math.max(a, c), d);
10+
int nc = land[i][2] + Math.max(Math.max(a, b), d);
11+
int nd = land[i][3] + Math.max(Math.max(a, b), c);
12+
a = na; b = nb; c = nc; d = nd;
13+
}
14+
return Math.max(Math.max(a, b), Math.max(c, d));
15+
}
16+
}
17+
```

0 commit comments

Comments
 (0)