leetcode算法题--数组中数字出现的次数

    科技2022-07-13  147

    原题链接:https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/

    vector<int> singleNumbers(vector<int>& nums) { int ret = 0; for (int n : nums) ret ^= n; int div = 1; while ((div & ret) == 0) div <<= 1; int a = 0, b = 0; for (int n : nums){ if (div & n) { a ^= n; } else { b ^= n; } } return vector<int>{a, b}; }
    Processed: 0.011, SQL: 8