摘要:
http://blog.sina.com.cn/s/blog_65c209580100u00j.html腾讯笔试题有1到10w这10w个数,去除2个并打乱次序,如何找出那两个数 收藏描述:有1到10w这10w个数,去除2个并打乱次序,如何找出那两个数。(不准用位图!!)位图解决:位图的方法如下假设待处理数组为A[10w-2]定义一个数组B[10w],这里假设B中每个元素占用1比特,并初始化为全0for(i=0;i <10w-2;i++){B[ A[i] ]=1}那么B中为零的元素即为缺少的数据这种方法的效率非常高,是计算机中最常用的算法之一其它方法:求和以及平方和可以得到结果,不过可能求 阅读全文
posted @ 2013-05-09 16:38
路人浅笑
阅读(669)
评论(0)
推荐(0)
摘要:
View Code 1 import java.util.*; 2 3 public class BinarySearch { 4 5 public static void main(String[] args) { 6 ArrayList<Integer> a = new ArrayList<Integer>(); 7 addIntegerInSequence(a, 1, 10); 8 print(a); 9 int pos = binarySearch(a, 10);10 if (pos != -... 阅读全文
posted @ 2013-05-09 16:07
路人浅笑
阅读(205)
评论(0)
推荐(0)
摘要:
View Code 1 import java.util.Random; 2 3 public class MergeSort { 4 private double[] bridge;//辅助数组 5 6 public void sort(double[] obj){ 7 if (obj == null){ 8 throw new NullPointerException("The param can not be null!"); 9 }10 bridge = new double[... 阅读全文
posted @ 2013-05-09 16:06
路人浅笑
阅读(264)
评论(0)
推荐(0)
摘要:
View Code 1 public class MySelectionSort { 2 3 // 直接选择排序 4 public void StraightSelectionSort(double[] sorted) { 5 for (int i = 1; i < sorted.length; i++) { 6 int minIndex = findMinIndex(sorted, i); 7 exchange(sorted, i, minIndex); 8 } 9 }10 11 ... 阅读全文
posted @ 2013-05-09 16:05
路人浅笑
阅读(213)
评论(0)
推荐(0)
摘要:
View Code 1 public class MyExchangeSort { 2 // 冒泡排序 3 public void BubbleExchangeSort(double[] sorted) { 4 for (int i = 1; i < sorted.length; i++) {//进行排序次数为数组长度-1 5 for (int j = 0; j < sorted.length - i; j++) {//从上到下进行排序,大数下沉 6 if (sorted[j] > sorted[j + ... 阅读全文
posted @ 2013-05-09 16:04
路人浅笑
阅读(201)
评论(0)
推荐(0)
摘要:
View Code 1 //升序 2 public class MyInsertSort { 3 // 直接插入排序 4 public void StraightInsertionSort(double[] sorted) { 5 int i, j; 6 for (i = 2; i < sorted.length; i++) { 7 if (sorted[i] < sorted[i - 1]) { 8 sorted[0] = sorted[i];// 设一监视哨 9 ... 阅读全文
posted @ 2013-05-09 16:02
路人浅笑
阅读(259)
评论(0)
推荐(0)

浙公网安备 33010602011771号