DP C# solution beats 100%


  • 1
    L
    public class Solution {
        public int MaxSubArray(int[] nums) {
             var result = 0;
                if (nums != null && nums.Length > 0)
                {
                    result = nums[0];
                    var fn_1 = nums[0];
                    for (int i = 1; i < nums.Length; i++)
                    {
                        fn_1 = Math.Max(nums[i], fn_1 + nums[i]);
                        result = Math.Max(fn_1, result);
                    }
                }
                return result;
        }
    }
    

Log in to reply
 

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