is it should be:
The O(n) solution is so brilliant! I could come up with the O(n^2) method, but I couldn't optimize it to O(n). Thanks a lot for sharing!
What's the exact/defined meaning for min and max in Pair class?
What (loop) invariant we are maintaining here?
whats the complexity of this sol ?O(N) ?
Same idea, another shorter version:
I think the inner while loop is the same as KMP's failure function's inner loop, so the time complexity is O(n).
@Uduse Shouldn't it be:
No one has replied
for your information:
Point.x = the minimum value till current iteration node
Point.y = the maximum value that appears after Point.x till current iteration node
@hamster Agree. Added O(n) solution using stack.
Disabled Categories are greyed out
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.