Python different solutions (DP).
   \n    # DP\n    def maxProfit1(self, prices):\n        if not prices:\n            return 0\n        loc = glo = 0\n        for i in xrange(1, len(prices)):\
       \n    # DP\n    def maxProfit1(self, prices):\n        if not prices:\n            return 0\n        loc = glo = 0\n        for i in xrange(1, len(prices)):\n            loc = max(loc+prices[i]-prices[i-1], 0)\n            glo = max(glo, loc)\n        return glo\n        \n    def maxProfit2(self, prices):\n        if not prices:\n            return 0\n        minPri, maxPro = prices[0], 0\n        for i in xrange(1, len(prices)):\n            minPri = min(minPri, prices[i])\n            maxPro = max(maxPro, prices[i]-minPri)\n        return maxPro\n        \n    # Reuse maximum subarray method\n    def maxProfit(self, prices):\n        if not prices or len(prices) == 1:\n            return 0\n        dp = [0] * len(prices)\n        for i in xrange(1, len(prices)):\n            dp[i] = prices[i]-prices[i-1]\n        glo = loc = dp[0]\n        for i in xrange(1, len(dp)):\n            loc = max(loc+dp[i], dp[i])\n            glo = max(glo, loc)\n        return glo
['Dynamic Programming', 'Python']