
编程
shanshanhi
这个作者很懒,什么都没留下…
展开
-
leetcode编程题-Single Number 1
1.Single NumberGiven 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 impleme原创 2016-03-23 17:28:38 · 531 阅读 · 0 评论 -
给定两个正整数(二进制形式表示)A和B,问把A变为B需要改变多少位(bit)?也就是说,整数A和B的二进制表示中有多少位是不同的?
#include <iostream>using namespace std;int countOne(int n)//统计二进制表示中所含1的个数{ int num=0; if(n==0) num=0; else { while(n) { n&=(n-1); num++原创 2016-03-23 13:29:49 · 1256 阅读 · 0 评论 -
利用数组实现的堆排序
void HeapSort(int a[],int n){ int i; for(i = n/2; i > 0; i--){//构建初始堆 HeapAdjust(a,i,n); } for(i = n; i > 1; i--){//不断输出最大元素进行排序,输出后继续调整 swap(a,1,i); HeapAdjust(a,1,i-1); }}void HeapA原创 2017-03-22 13:38:10 · 1567 阅读 · 1 评论