LeetCode|413. Arithmetic Slices
A zero-indexed array A consisting of N numbers is given. A slice of that array is any pair of integers (P, Q) such that 0 <= P < Q < N. A slice (P, Q) of array A is called arithmetic if the sequence: A[P], A[p + 1], ..., A[Q - 1], A[Q] is arithmetic. In particular, this means that P + 1 < Q. The function should return the number of arithmetic slices in the array A. Example: A = [1, 2, 3, 4] return: 3, for 3 arithmetic slices in A: [1, 2, 3], [2, 3, 4] and [1, 2, 3, 4] itself. Solution 本题是一道动态规划问题。我们用动态规划的思想来解答这个问题。 这道题是要找出一个等差数列中有多少子等差数列。那么我们可以提出两个问题。 什么是等差数列以及等差数列最少需要几个数 一个任意数组有多少个子数组