题解:
使用二分查找
class Solution {
public:int minArray(vector<int>& numbers) {int low = 0;int high = numbers.size() - 1;while (low < high) {int pivot = low + (high - low) / 2;if (numbers[pivot] < numbers[high]) {high = pivot;}else if (numbers[pivot] > numbers[high]) {low = pivot + 1;}else {high -= 1;}}return numbers[low];}
};
题解:
循环+位运算
class Solution {
public:int hammingWeight(uint32_t n) {int ret = 0;while (n) {n &= n - 1;ret++;}return ret;}
};