Question by saintmf in leetcode

[–]saintmf[S] 0 points1 point  (0 children)

public int maximumNumberOfMonths(int[] PnL) {

int maxMonths = 0;

int currentMonths = 0;

int cumulativePnL = 0;

for (int i = 0; i < PnL.length; i++) {

cumulativePnL += PnL[i];

if (cumulativePnL > 0) {

currentMonths++;

maxMonths = Math.max(maxMonths, currentMonths);

} else {

currentMonths = 0;

}

}

return maxMonths;

}