Description: Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Example 1: Input: nums = [-2,1,-3,4,-1,2,1,-5,4]
Explanation: [4,-1,2,1] has the largest sum = 6. Solution 1: Dynamic Programming. Time complexity O(N), N= Length of nums. In Dynamic Proggramming, solution of i+1 step is close related to the solution of i step and i+1 value. In this problem, we have to consider if i+1 value is the new head of a contiguous subarray. The head of a contiguous subarray would fulfill the requirement that its value x would greater than the summation of x and tempMax. And each time, we have to check if the updated tempMax is greater than the res value.