121.Best Time to Buy and Sell Stock Posted on 2017-09-13 | In LeetCode Solution 1: accepted 3msDP.Time: O(n)Space: O(1) 12345678910111213public class Solution { public int maxProfit(int[] prices) { if (prices.length < 2) return 0; int max = 0; for (int i = 1; i < prices.length; i++) { if (prices[i] > prices[i-1]) { max = Math.max(max, prices[i] - prices[i-1]); prices[i] = prices[i-1]; } } return max; }}