Medium
Quiz
#413 Arithmetic Slices
APPROACH
An arithmetic subarray has at least three elements and a constant difference between every pair of consecutive elements (for example [1,3,5,7,9], [7,7,7,7], [3,-1,-5,-9]).
Given an integer array nums, count and return the total number of arithmetic contiguous subarrays.
Example 1:
Input: nums = [1,2,3,4]
Output: 3
Explanation: We have 3 arithmetic slices in nums: [1, 2, 3], [2, 3, 4] and [1,2,3,4] itself.
Example 2:
Input: nums = [1]
Output: 0
1 of 4
1:00
What is the optimal approach for this problem?