public int maxSubArray(int[] A) {
    	if (A.length == 0)
    		return 0;
    	int max = Integer.MIN_VALUE;
    	for (int i = 0; i < A.length; i ++)
    		max = Math.max(max, A[i]);
    	
    	if (max < 0)
    		return max;
    	
    	int sum = 0;
      
    	for (int i = 0; i < A.length; i++)
    	{
    		sum +=A[i];
    		if (sum > max)
    			max = sum;
    		else if (sum < 0)
    			sum = 0;
    	}

    	return max;
    }