首页 > 其他 > 详细

找到数组中唯一重复的数

时间:2014-05-19 12:25:05      阅读:317      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
#include<iostream>
#include<algorithm>
#include<numeric>
using namespace std;

int helper1(int a[],int n)
{
  int sum = accumulate(a,a+n,0);
  int sum2 = n*(n-1)/2;
  return sum-sum2;
}

int helper2(int a[],int n)
{
  int bitor = a[0]^0;
  for(int i = 1;i< n;i++)
  {
      bitor ^= a[i];
      bitor ^= i;
  }
  return bitor;
}

int main()
{
    int a[] = {1,2,3,4,5,5};
    cout<<helper1(a,6)<<endl;
    cout<<helper2(a,6)<<endl;
}
bubuko.com,布布扣

有没有想过如果没有要求是连续的整形的话,怎么办?

关于等比数列和等差数列的求和公式和递归公式,你是不是要补补?

an=a1×q^(n-1);

 

Sn=n×a1 (q=1)

 

Sn=a1(1-q^n)/(1-q) =(a1-a1q*n)/(1-q) (q≠1)

 

S∞=a1/(1-q) (n-> ∞)(|q|<1)
 
an=a1+(n-1)d
  前n项和公式
:Sn=na1+n(n-1)d/2
  若公差d=1时:Sn=(a1+an)n/2

 

找到数组中唯一重复的数,布布扣,bubuko.com

找到数组中唯一重复的数

原文:http://www.cnblogs.com/berkeleysong/p/3735568.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!