35. Search Insert Position/in java/src/Main.java
<reponame>youssef232/Problem_solvingpublic class Main {

    public static void main(String[] args) {
        int[] nums = {5,4,-1,7,8};
        System.out.println(maxSubArray(nums));
    }

    public static int maxSubArray(int[] nums) {
        int maxSum = nums[0];
        int output = nums[0];
        for (int i = 1; i < nums.length; i++) {
            maxSum = Math.max(nums[i], maxSum + nums[i]);
            output = Math.max(maxSum, output);
        }
        return output;
    }
}
