public int minSubArray(ArrayList<Integer> nums) {
        // write your code
        int[] dp = new int[nums.size()];
        dp[0] = nums.get(0);
        int min = dp[0];
        for (int i = 1; i < nums.size(); ++i) {
            dp[i] = Math.min(dp[i - 1] + nums.get(i), nums.get(i));
            min = Math.min(min, dp[i]);
        }
        return min;
    }