Skip to content

Commit d19d9a3

Browse files
authored
Merge pull request #1396 from AlgorithmWithGod/ksinji
[20251113] PGM / LV3 / 단속카메라 / 강신지
2 parents 8803bd9 + 4234d97 commit d19d9a3

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

ksinji/202511/11 PGM 도둑질.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
```java
2+
class Solution {
3+
public int solution(int[] money) {
4+
int n = money.length;
5+
6+
int A0 = 0;
7+
int A1 = 0;
8+
9+
int B0 = 0;
10+
int B1 = money[0];
11+
12+
for (int i = 1; i < n; i++) {
13+
int newA0 = Math.max(A0, A1);
14+
int newA1 = A0 + money[i];
15+
A0 = newA0; A1 = newA1;
16+
17+
if (i <= n - 2) {
18+
int newB0 = Math.max(B0, B1);
19+
int newB1 = B0 + money[i];
20+
B0 = newB0; B1 = newB1;
21+
}
22+
}
23+
24+
int bestA = Math.max(A0, A1);
25+
int bestB = Math.max(B0, B1);
26+
return Math.max(bestA, bestB);
27+
}
28+
}
29+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
```java
2+
import java.util.*;
3+
4+
class Solution {
5+
public int solution(int[][] routes) {
6+
Arrays.sort(routes, (a, b) -> Integer.compare(a[1], b[1]));
7+
8+
int answer = 0;
9+
int camera = Integer.MIN_VALUE;
10+
11+
for (int[] r : routes){
12+
int s = r[0];
13+
int e = r[1];
14+
15+
if (camera < s){
16+
camera = e;
17+
answer++;
18+
}
19+
}
20+
21+
return answer;
22+
}
23+
}
24+
```

0 commit comments

Comments
 (0)