高效存储为序列可以使用位积,由于位集将位包装在字节里,所以位集要比使用Boolean对象的ArrayList更高效. 自己的代码,素数是false public class Sieve { @Test public void testMethod(){ int n = 200; long start = System.currentTimeMillis(); BitSet b = new BitSet(n+1); System.out.println(b.size()); for(int i =
这是我学习唐峻,李淳的<C/C++常用算法第一天> 1.8.1. 查找数字: 程序随机生成一个拥有20个整数数据的数组,然后输入要查找的数据.接着,可以采用醉简单的逐个对比的方法进行查找,也就是顺序查找的方法,下面给出该算法完整的C语言代码: #include <stdio.h> #include <stdlib.h> #include <time.h> #define N 20 int main(){ int arr[N],x,n,i; int f=-1;
题目:二分查找 描述:给定一个排序的整数数组(升序)和一个要查找的整数target,用O(logn)的时间查找到target第一次出现的下标(从0开始),如果target不存在于数组中,返回-1. class Solution { public: /** * @param nums: The integer array. * @param target: Target number to find. * @return: The first position of target. Positio