a different idea to solve it beat 98% python


  • 0
    L

    just need to diff the list and sum the positive numbers
    '''
    class Solution(object):
    def maxProfit(self, prices):
    """
    :type prices: List[int]
    :rtype: int
    """
    p=[]
    out=0
    for i in range(len(prices)-1):
    p.append(prices[i+1]-prices[i])
    for j in p:
    if j>0:
    out+=j
    return out
    '''


Log in to reply
 

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