Skip to content

Commit febc2ec

Browse files
committed
Update comment for diff calculateion
1 parent 080e8a7 commit febc2ec

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

Cpp/maxProfit.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class Solution {
4040
// then it should be discarded
4141
// that is why maximum of (diff+currentMax) and diff
4242
// is checked here
43+
// For instance 4 6 1 2 3 5 in this array after 6 the
44+
// algorithm should be restarted because max diff is 5 -1 = 4.
45+
// so max(-5+3 , 2-1) = 1, so calculation will start from 1.
4346
currentMax = std::max(diff+currentMax, diff);
4447
max = std::max(currentMax, max);
4548
}

0 commit comments

Comments
 (0)