题目:
题解:
class Solution {public int numberOfArithmeticSlices(int[] nums) {int ans = 0;int n = nums.length;Map<Long, Integer>[] f = new Map[n];for (int i = 0; i < n; ++i) {f[i] = new HashMap<Long, Integer>();}for (int i = 0; i < n; ++i) {for (int j = 0; j < i; ++j) {long d = 1L * nums[i] - nums[j];int cnt = f[j].getOrDefault(d, 0);ans += cnt;f[i].put(d, f[i].getOrDefault(d, 0) + cnt + 1);}}return ans;}
}