4 millisecond C Code


  • 0
    V
    int maxSubArray(int* nums, int numsSize) 
    {
        int i,max=0,max2=0,flag=0,min=0;
        int f;
        for(i=0;i<numsSize;i++)
        {
            if(max+nums[i]<0)
            max=0;
            else
            {
            flag=1;
            max=max+nums[i];
            }
            if(max>max2)
            max2=max;
        }
        if(flag==0)
        {
            max2=nums[0];
            for(i=0;i<numsSize;i++)
        {
            if(nums[i]>max2)
            max2=nums[i];
        }
        }
        return max2;
            
    }

Log in to reply
 

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