<commit_before>/**
 * @since 2017-03-22 14:26:29
 * @author vivaxy
 * @see https://leetcode.com/problems/maximum-subarray/

 Find the contiguous subarray within an array (containing at least one number) which has the largest sum.

 For example, given the array [-2, 1, -3, 4, -1, 2, 1, -5, 4],
 the contiguous subarray [4, -1, 2, 1] has the largest sum = 6.

 */

/**
 * TODO UNDERSTAND
 * 证明：
 *  数组 Array[m, ..., n-1] 中的最大子数组和的值为 A
 *  那么 Array[m, ..., n] 中最大子数组和的值为 A + Array[n] 或者为 Array[n]
 *  我们的算法从 Array[0] 开始进行比较
 * @param {number[]} nums
 * @return {number}
 */
var maxSubArray = function(nums) {
    var max = nums[0];
    var currentMax = nums[0];
    for (var from = 1; from < nums.length; from++) {
        var n = nums[from];
        if (currentMax > 0) {
            currentMax = currentMax + n;
        } else {
            currentMax = n;
        }
        if (currentMax > max) {
            max = currentMax;
        }
    }
    return max;
};
<commit_msg>chore:<commit_after>/**
 * @since 2017-03-22 14:26:29
 * @author vivaxy
 * @see https://leetcode.com/problems/maximum-subarray/

 Find the contiguous subarray within an array (containing at least one number) which has the largest sum.

 For example, given the array [-2, 1, -3, 4, -1, 2, 1, -5, 4],
 the contiguous subarray [4, -1, 2, 1] has the largest sum = 6.

 */

/**
 * TODO UNDERSTAND
 * 证明：
 *  数组 Array[m, ..., n-1] 中的最大子数组和的值为 A
 *  那么 Array[m, ..., n] 中最大子数组和的值为 A + Array[n] 或者为 Array[n]
 *  我们的算法从 Array[0] 开始进行比较
 * @see https://leetcode.com/submissions/detail/97926397/
 * @param {number[]} nums
 * @return {number}
 */
var maxSubArray = function(nums) {
    var max = nums[0];
    var currentMax = nums[0];
    for (var from = 1; from < nums.length; from++) {
        var n = nums[from];
        if (currentMax > 0) {
            currentMax = currentMax + n;
        } else {
            currentMax = n;
        }
        if (currentMax > max) {
            max = currentMax;
        }
    }
    return max;
};

{'fraction_non_alphanumeric': 0.15027458811782327, 'fraction_numerical': 0.03794308537194209, 'mean_word_length': 2.2427184466019416, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1159485', 'n_tokens_mistral': 838, 'n_tokens_neox': 768, 'n_words': 222}