摘要:
二分查找算法 二分查找算法的核心就是在查找的一堆有序数据中,使用\(\log_n\)的时间复杂度进行查找,最基本的算法代码如下: public static int binarySearch(int[] a, int target) { if (a.length == 0) return -1; i 阅读全文
摘要:
如何快速求一个整数使用二进制表示时1的个数? 这里给出一个很简单的方法,首先看代码: public int findBin1Count(int n) { int res = 0; while (n != 0) { if ((n & 1) == 1) res++; n >>= 1; } return 阅读全文