I don't konw why answer is 6?

  • 1

    The case [6,1,3,2,4,7] which expected ouput is 6.My output is 7.My solution is,at the second day i buy,and the third day sell,the fourth day buy it ,the sixth day sell it .Why the answer is 6?

  • 2

    The question is equivalent to the following:

    Find the value that is maximum of Aj – Ai, where i < j.

    In the input case [6,1,3,2,4,7] buy when stock price is 1 and sell when stock price is 7, and the maximum profit is 6.

  • 0

    thanks you,i understood.

  • 0

    Only ONE transaction is allowed if you read the problem carefully.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.