- 什么是差分数组?
- 差分数组的构建
int[] res = new int[diff.length];
// 根据差分数组构造结果数组
res[0] = diff[0];
for (int i = 1; i < diff.length; i++) {
res[i] = res[i - 1] + diff[i];
}
- 差分数组的应用
Leetcode- 区间加法(中等)
- 航班预订统计(中等)
- 拼⻋(中等)
int[] res = new int[diff.length];
// 根据差分数组构造结果数组
res[0] = diff[0];
for (int i = 1; i < diff.length; i++) {
res[i] = res[i - 1] + diff[i];
}