We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents f09ae8e + cad609f commit 3465583Copy full SHA for 3465583
ksinji/11 PGM 도둑질.md
@@ -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
+```
0 commit comments