Description
An arithmetic slice is at least 3 consecutive elements with constant difference. Return the number of arithmetic slices in the array.
Examples
Input:
nums = [1,2,3,4]Output:
3Explanation:
[1,2,3],[2,3,4],[1,2,3,4].
Input:
nums = [1]Output:
0Explanation:
Edge case returning zero.
Input:
nums = [1,3,5,7,9,11]Output:
10Explanation:
All consecutive subsequences of length ≥ 3 form arithmetic slices with common difference 2: [1,3,5], [3,5,7], [5,7,9], [7,9,11], [1,3,5,7], [3,5,7,9], [5,7,9,11], [1,3,5,7,9], [3,5,7,9,11], [1,3,5,7,9,11].
Constraints
- •
1 ≤ nums.length ≤ 5000