@@ -0,0 +1,819 @@
+/**%0A *%09Say you have an array for which the ith element is the price of a given stock on day i.%0A *%0A *%09If you were only permitted to complete at most one transaction %0A *%09(ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.%0A *%0A *%09Author: matao%0A *%0A */%0A%0Apublic class BestTimeToBuyAndSellStock %7B%0A%09public static int maxProfit(int%5B%5D prices) %7B%0A%09%09if (prices == null %7C%7C prices.length == 0) %7B%0A%09%09%09return 0;%0A%09%09%7D%0A%09%09int n = prices.length;%0A%09%09int min = Integer.MAX_VALUE;%0A%09%09int profit = 0;%0A%09%09for (int i = 0; i %3C n; i++) %7B%0A%09%09%09min = prices%5Bi%5D %3C min ? prices%5Bi%5D : min;%0A%09%09%09profit = (prices%5Bi%5D - min) %3E profit ? prices%5Bi%5D - min : profit;%0A%09%09%7D%0A%09%09return profit;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A    %09int%5B%5D prices = %7B3, 2, 3, 1, 2%7D;%0A    %09System.out.println(maxProfit(prices));%09%0A    %7D%0A%7D

add Best Time To Buy And Sell Stock solution