码迷,mamicode.com
首页 > 其他好文 > 详细

找到数组中唯一重复的数

时间:2014-05-19 12:25:25      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   c   java   

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

找到数组中唯一重复的数

标签:style   blog   class   code   c   java   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!