package bianchengti; /* * 在由N个元素构成的集合S中,找出最小元素C,满足C=A-B, * 其中A,B是都集合S中的元素,没找到则返回-1 */ public class findMinValue { //快速排序 public static void sort(int a[], int low, int hight) { if (low > hight) { return; } int i, j, key; i = low; j = hight; key = a[i]
Given an array of integers, every element appears twice except for one. Find that single one. Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? 数组中除了某个元素出现一次,其他都出现两次,找出只出现一次的元素. 一个数字和自己异或
unique函数的功能是:去除相邻的重复元素(只保留一个). 函数参数:unique(first,last,compare); //first为容器的首迭代器,last为容器的末迭代器,compare为比较函数(可略写). int N ; while(cin>>N){ for(int i=1 ;i<=N ;i++) cin>>num[i] ; sort(num+1,num+1+N) ; //先排序 int M=unique(num+1,num+1+N)-(num+1) ; c