❔ Maximum Subarray Leetcode Help
I'm getting the wrong answer with test case
Im not sure what I should be doing differently but I think I may be misunderstanding something with Kadane's Algorithm and negative numbers
C#
public int MaxSubArray(int[] nums) {
//declarations
int max_ending_here = nums[0];
int max_so_far = nums[0];
//logic
for(int i = 1; i < nums.Length; i++)
{
max_ending_here += nums[i];
if(max_ending_here > max_so_far)
{
max_so_far = max_ending_here;
}
}
return max_so_far;
}nums =
[-2,1,-3,4,-1,2,1,-5,4]