classSolution{public:intminOperationsMaxProfit(vector<int>&customers,intboardingCost,intrunningCost){intwaiting=0;intprofit=0;intmaxProfit=0;introtate=0;intmaxRotate=-1;inti=0;while(waiting>0||i<customers.size()){if(i<customers.size())waiting+=customers[i++];// onboard new customersconstintnewOnboard=min(waiting,4);waiting-=newOnboard;profit+=newOnboard*boardingCost-runningCost;++rotate;if(profit>maxProfit){maxProfit=profit;maxRotate=rotate;}}returnmaxRotate;}};
JAVA
classSolution{publicintminOperationsMaxProfit(int[]customers,intboardingCost,intrunningCost){intwaiting=0;intprofit=0;intmaxProfit=0;introtate=0;intmaxRotate=-1;inti=0;while(waiting>0||i<customers.length){if(i<customers.length)waiting+=customers[i++];// onboard new customersfinalintnewOnboard=Math.min(waiting,4);waiting-=newOnboard;profit+=newOnboard*boardingCost-runningCost;++rotate;if(profit>maxProfit){maxProfit=profit;maxRotate=rotate;}}returnmaxRotate;}}
Login to Codeflu
Log in to stay update and get notify on new arrivals.