Prefix and
A number of column A, it is a prefix number sequence S can be deduced by mathematically:
Part and
A number of columns and number of the interval and the subscripts a, namely:
S[i, j]=S[j] - S[i - 1]
Prefix and with some application scenarios and
Given m intervals, each seeking the number of and interval;
Violence Solution: m cycles, internal recycling that bracket, this solution in a small amount of data scene no problem, if the value is large, will cause a timeout.
Prefix and Solution: prefix and the first calculation, and then the cycle m times, each interval portion and seek
The difference
A series A: 1,2,3,4,5, as its difference number B: 1,1,1,1,1, has the following characteristics:
1, the number of columns and a B prefix S [i] = A [i]
2, the number of columns in the i-th item A plus B k corresponds to the number of columns of the first item plus k i, i + 1-k items Save
3, the number of columns of A plus key k i to j, the number of columns corresponding to the i-th item plus B k, j + 1-k items Save
Stay button corresponding to the exercises
https://leetcode-cn.com/problems/corporate-flight-bookings/
https://leetcode-cn.com/problems/subarray-sum-equals-k/