Skip to content

Commit b9cb5af

Browse files
authored
Create Minimum Levels to Gain More Points.java
1 parent 8688def commit b9cb5af

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+
class Solution {
2+
public int minimumLevels(int[] possible) {
3+
int n = possible.length;
4+
int totalScore = 0;
5+
for (int i = n - 1; i >= 0; i--) {
6+
totalScore += possible[i] == 1 ? 1 : -1;
7+
}
8+
int score = 0;
9+
for (int i = 0; i < n - 1; i++) {
10+
score += possible[i] == 1 ? 1 : -1;
11+
if (score > totalScore - score) {
12+
return i + 1;
13+
}
14+
}
15+
return -1;
16+
}
17+
}

0 commit comments

Comments
 (0)