sum
to 0 to keep track of the total number of arithmetic subarrays.count
to 0 to keep track of the current run of consecutive elements forming an arithmetic subarray.nums[i] - nums[i-1]
is the same as nums[i-1] - nums[i-2]
).count
.count * (count + 1) / 2
to sum
, and reset count
to 0.count * (count + 1) / 2
to sum
to account for the last run.sum
.