# why i cannot pass this test cases

• ``````int numberOfArithmeticSlices(vector<int>& cnum) {
int size = cnum.size();
vector<long long> nums(size,0);
for (int i = 0; i < size; ++i)
nums[i] = cnum[i];
vector<unordered_map<long long, int>> arithMap(size);	//记录等差为key的时候，在该等差数列中是第value个数
int count = 0;
for (int i = 1; i < size; ++i)
{
for (int j = i - 1; j >= 0; --j)
{
long long distance = nums[i] - nums[j];
if (arithMap[j].find(distance) == arithMap[j].end())
arithMap[i][distance] = 2;	//为该等差 的 等差数列的第2个数
else
arithMap[i][distance] = (arithMap[j][distance] + 1);
count += (arithMap[i][distance] - 2);
}
}
return count;
}
``````

test case:
[79,20,64,28,67,81,60,58,97,85,92,96,82,89,46,50,15,2,36,44,54,2,90,37,7,79,26,40,34,67,64,28,60,89,46,31,9,95,43,19,47,64,48,95,80,31,47,19,72,99,28,46,13,9,64,4,68,74,50,28,69,94,93,3,80,78,23,80,43,49,77,18,68,28,13,61,34,44,80,70,55,85,0,37,93,40,47,47,45,23,26,74,45,67,34,20,33,71,48,96]

Output: 745
Expected: 1030

• give u a sample test, like [2, 2, 3, 4].
when i==2 and j == 1, u'r code will set arithMap[2][1] = 2.
when i==2 and j == 0, u'r code will set arithMap[2][1] = 2.
when i==3 and j == 2, u'r code will set arithMap[3][1] = 3.
So u get one [2, 3, 4], but here has two [2, 3, 4].

• @layor thank you so much, you figure it out perfectly

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.