There is a problem here, what do you guys think?


  • 0

    There is a problem here, what do you guys think?

    Test case: [10, 11, 1, 10]

    The answer is (11-10) + (10-1) = 10

    But I think the fact should be:

    1. [10] -> buy
      number of stocks = 1
      remainder = 0

    2. [11] -> sell
      number of stocks = 0
      remainder = 11

    3. [1] -> buy
      number of stocks = 11
      remainder = 0

    4. [10] -> sell
      number of stocks = 0
      remainder = 110

    so the result should be: 110 - 10 = 100

    Give me some suggestions, Thanks!


  • 0
    Z

    The numbers in array is the price of the stock, we can see the number of stock always as 1 when has a transaction. Right? I not quite understand the step 4 you mentioned in your test case, why the reminder is 110?


Log in to reply
 

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