We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 080e8a7 commit febc2ecCopy full SHA for febc2ec
Cpp/maxProfit.cpp
@@ -40,6 +40,9 @@ class Solution {
40
// then it should be discarded
41
// that is why maximum of (diff+currentMax) and diff
42
// 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.
46
currentMax = std::max(diff+currentMax, diff);
47
max = std::max(currentMax, max);
48
}
0 commit comments