leetcode53

public class Solution {
    public int MaxSubArray(int[] nums) {
        int max = int.MinValue;
            int sum = 0;
            for (int i = 0; i < nums.Length; i++)
            {
                if (sum < 0)
                {
                    sum = nums[i];
                }
                else
                {
                    sum += nums[i];
                }
                if (sum > max)
                {
                    max = sum;
                }
            }
            return max;
    }
}

https://leetcode.com/problems/maximum-subarray/#/description

转载于:https://www.cnblogs.com/asenyang/p/6732698.html

你可能感兴趣的:(leetcode53)