人人网算法类笔试题和面试题答案汇总(2)

招聘笔试题2018-11-22李天扬老师

  {

  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

相关推荐

猜你喜欢

大家正在看

换一换