Maximum Profit of Operating a Centennial Wheel LeetCode solution in Java

1
class Solution {
2
public int minOperationsMaxProfit(int[] customers, int boardingCost, int runningCost) {
3
int rotatn = 0;
4
int cust = 0;
5
int profit = Integer.MIN_VALUE;
6
int prRotn = 0;
7
int cSit = 0;
8

9
for (int i = 0; i < customers.length; i++) {
10
cust += customers[i];
11
rotatn++;
12

13
int prof = 0;
14
if (cust >= 4) {
15

16
cust = cust - 4;
17
cSit += 4;
18
} else {
19
cSit += cust;
20
cust = 0;
21
}
22
prof = cSit * boardingCost - rotatn * runningCost;
23
if (prof > profit) {
24
profit = prof;
25
prRotn = rotatn;
26
}
27
}
28
while (cust > 0) {
29
rotatn++;
30

31
int prof = 0;
32
if (cust >= 4) {
33
cust = cust - 4;
34
cSit += 4;
35
} else {
36
cSit += cust;
37
cust = 0;
38
}
39
prof = cSit * boardingCost - rotatn * runningCost;
40

41
if (prof > profit) {
42
profit = prof;
43

44
prRotn = rotatn;
45
}
46
}
47
if (profit > 0) return prRotn;
48
return -1;
49
}
50
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0