public class Solution {
    public int FindGreatestSumOfSubArray(int[] array) {
        if(array == null || array.length == 0){
            return -1;
        }

        int[] dp = new int[array.length];
        int maxV = Integer.MIN_VALUE;

        for(int i = 0; i < array.length; ++i){
            if(i == 0){
                dp[i] = array[i];
            }else{
                if(dp[i - 1] >= 0){
                    dp[i] = dp[i - 1] + array[i];
                }else{
                    dp[i] = array[i];
                }
            }
            if(maxV < dp[i]){
                maxV = dp[i];
            }
        }

        return maxV;
    }
}