Wrong answer given....expected 0, provided 1...input [1,2]....you buy at 2 and sell at 1,


  • 0
    B

    public class Solution {
    public int maxProfit(int[] prices) {
    if (prices.length < 1) {
    return 0;
    }
    Arrays.sort(prices);
    int profit;
    profit = prices[prices.length-1] - prices[0];
    return profit;
    }
    }


  • 0

    The series of prices is based on time stream
    So you can't sort it, the order is a fact.


Log in to reply
 

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