更新时间:2018-11-22 16:00作者:王新老师
{
int *low = NULL;
int *high = NULL;
int i = 0;
int result = -1;
if(a == NULL || len < 2)
{
return result;
}
if(a[0] >= k)
{
return result;
}
while(a[i] <= k && i < len)
{
i++;
}
low = a;
high = a + i - 1;
while(low < high)
{
*num1 = *low;
*num2 = *high;
if((*low + *high) == k)
{
result = 0;
break;
}
else if((*low + *high) > k)
{
high--;
}
else if((*low + *high) < k)
{
low++;
}
}
return result;
}
解法二:
#include
using namespace std;
int hash_table[100];
bool judge(int *a, int len, int x)
{
memset(hash_table, 0, sizeof(hash_table));
for (int i=0; i