通过map,往前查找,有没有和当前值和为指定值的
int main()
{
int testarr[] = {1,2,3,4,5,6,7,8,9,10};
int target = 10;
std::map<int, int> testMap;
for(int i=0; i < 10; ++i)
{
int temp = target - testarr[i];
if(testMap.find(temp) != testMap.end())
{
printf("%d,%d\n", testarr[i], temp);
}
else
{
testMap[testarr[i]] = i;
}
}
return 0;
}

814

被折叠的 条评论
为什么被折叠?



