一:lowbit()计算二进制中1的个数
#include <iostream>using namespace std;const int N = 100010;int n;int a[N];int lowbit(int x) {return x & -x; // 这个题目的关键,实现返回某个数二进制的最后一个1。例如9---1001,返回就是1 8 ---- 1000返回就是8}int main() {cin >> n;while (n--) {int x;scanf("%d", &x);int res = 0;while (x) {x -= lowbit(x), res++; // 这里考察了运算符的优先级,这种写法也需要学习。}cout << res << " ";}return 0;}
二:位运算之异或运算


class Solution {public:int singleNumber(vector<int>& nums) {int res = 0;for (auto& c : nums){res ^= c;}return res;}};
三:区间和
没有找到相应的题目,只能在clion上实验,如果明天面试过了,能拿工资就买一个正版。
