class Solution {
public int numberOfArithmeticSlices(int[] nums) {
int n = nums.length;
Map<Long, Integer>[] dp = new HashMap[n];
int res = 0;
for (int i = 0; i < n; i++) {
dp[i] = new HashMap<>();
for (int j = 0 ; j < i ; j++) {
long diff = (long)nums[i] - (long)nums[j];
// dp[i][diff] = dp[j][diff]+1
int value = dp[i].getOrDefault(diff, 0) + dp[j].getOrDefault(diff, 0) + 1;
dp[i].put(diff, value);
res += dp[j].getOrDefault(diff, 0);
}
}
return res;
}
}
/*
[2,4, 6, 8, 10]
2:1
2:2
res+1[2,4,6]
res+2 2:3 [2,4,6,8. 4,6,8]
*/