Get the maxprofit of buy-and-sell stock using greedy method