Skip to content

Commit 080e8a7

Browse files
committed
Update comment for comparasion with diff
1 parent 0c0804b commit 080e8a7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Cpp/maxProfit.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ class Solution {
3636
{
3737
int diff = prices[i+1] - prices[i];
3838
if(diff == 0) continue;
39+
// if previous profit is less than the current one (negative profit = loss)
40+
// then it should be discarded
41+
// that is why maximum of (diff+currentMax) and diff
42+
// is checked here
3943
currentMax = std::max(diff+currentMax, diff);
4044
max = std::max(currentMax, max);
4145
}

0 commit comments

Comments
 (0)