# 210721
# 参考
# 原子笔记
最大子数组问题
// 最大子数组问题:找出数组中和最大的连续子数组,并返回最大和 // 复杂度 O(n) function getMaxSubSum(arr) { let maxSum = 0; let partialSum = 0; for (const item of arr) { partialSum += item; maxSum = Math.max(maxSum, partialSum); if (partialSum < 0) partialSum = 0; } return maxSum; }1
2
3
4
5
6
7
8
9
10
11
12
13
14原位操作的数组方法:
splice(返回删除的项组成的数组)、sort、reverse、copyWithin。创建新数组的方法:
slice、concat、map。