Java simple solution
public int maxProfit(int[] prices) {\n    \n        int le = prices.length, maxD = 0, min = Integer.MAX_VALUE;\n    \n        for (int i = 0; i < le; i++){ \n  
  public int maxProfit(int[] prices) {\n    \n        int le = prices.length, maxD = 0, min = Integer.MAX_VALUE;\n    \n        for (int i = 0; i < le; i++){ \n            min = Math.min(min, prices[i]);\n            maxD = Math.max(maxD, prices[i] - min);\n        }\n\n        return maxD;       \n}
[]