Solved MaxProfit in java