int copy = num;
if(copy == 0) {
return ++len;
}
while(copy != 0) {
copy /= 10;
len++;
}
return len;
}
public static void main(String[] args) {
System.out.println("----------- Now start computing... -----------");
long s = System.currentTimeMillis();
VampireNumber.find(0, Integer.MAX_VALUE);
long f = System.currentTimeMillis();
System.out.println("----- Computing finished, time used: " + (f - s) + " ms. -----");
}
}
上述程序用于求出0与Integer.MAX_VALUE之间的所有吸血鬼数,经实际测试(机器为四核3.3G的CPU,4G内存),运行时间为746259ms,超过了12分钟,在这么高配置的机器中运行速度还这么慢,可见整个算法的低效程度,有待优化~~~ ^_^
本人冒天下之大不韪,在各位算法大牛面前班门弄斧,如果各位要喷的话,请轻点喷,谢谢~~~ ^_^
作者 ini_always