LeetCode Maximum Subarray

BabbleDay posted @ 2015年7月17日 17:03 in 刷题防身 with tags python DP array leetcode Maximum Subarray , 1105 阅读

最基本DP

def maxSubArray(self, nums):
        output = [nums[0]]
        for i in range(1,len(nums)):
            output.append( max(output[i-1]+nums[i],nums[i]) )
        return max(output)

 

优化:用变量代替数组

def maxSubArray(self, nums):
        t, rtn = nums[0], nums[0]
        for i in range(1, len(nums)):
            t = max(t+nums[i], nums[i])
            rtn = max(rtn, t)
        return rtn
Avatar_small
Click Here To Know M 说:
2019年12月24日 21:31

All the relevant and related procedures can be tracked online methods and since the work now a day is accomplished with minimum time taking here via an agent, the commission consistent in the ratio of percent is also minimum as well, in the numbers to around 1-3 consistent with percent Click Here To Know More.

Avatar_small
SCERT Uttar Pradesh 说:
2023年9月04日 20:30

Uttar Pradesh State Primary School Students who are Eagerly Searching for the UPMSP 2nd Revised Syllabus 2024 can Stay on this webpage.Complete Subject wise SCERT UP Syllabus 2024 Pdf Format are Attached in the Following Sections for Free of Cost, Therefore, All the Students who are Going to Appear for the Examination can make use of the Information Provided here and Accordingly practice SCERT Uttar Pradesh 2nd Syllabus 2024 Complete Uttar Pradesh Syllabus 2024 given in order to give their best in the Examination.Uttar Pradesh Primary School Parents can use the Syllabus to Understand the Concepts and Prepare their Children for the Exam, Accordingly, The UP Board Syllabus 2024 All Subject Chapter Wise Students Prepare for the Upcoming Exam.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter