随笔分类 - 数据结构与算法 / 位运算
摘要:1.题目 题目地址(187. 重复的DNA序列 - 力扣(LeetCode)) https://leetcode.cn/problems/repeated-dna-sequences/ 题目描述 DNA序列 由一系列核苷酸组成,缩写为 'A', 'C', 'G' 和 'T'.。 例如,"ACGAAT
阅读全文
摘要:1. 题目 题目地址(1486. 数组异或操作 - 力扣(LeetCode)) https://leetcode.cn/problems/xor-operation-in-an-array/?envType=study-plan-v2&envId=primers-list 题目描述 给你两个整数,n
阅读全文
摘要:1.性质 对于第五条进行解释, 可以看到如下例子, 四者异或运算结果位0(有1的位都出现了两次), 而 *i 也只是将位进行平移而已, 并不影响异或结果 011 010 001 000 2.补充 2.1 去除最低位1 举例: (a为高位部
阅读全文
摘要:1. 题目 题目地址(231. 2 的幂 - 力扣(LeetCode)) https://leetcode.cn/problems/power-of-two/?envType=study-plan-v2&envId=primers-list 题目描述 给你一个整数 n,请你判断该整数是否是 2 的幂
阅读全文
摘要:1.题目介绍 题目地址(645. 错误的集合 - 力扣(LeetCode)) https://leetcode.cn/problems/set-mismatch/ 题目描述 集合 s 包含从 1 到 n 的整数。不幸的是,因为数据错误,导致集合里面某一个数字复制了成了集合里面的另外一个数字的值,导致
阅读全文
摘要:1.题目介绍 2.题解 2.1 枚举 思路 这里你只要知道 num % 2 相当于是取到二进制最后一位, num / 2 是将二进制整体向右推移一位即可 代码 class Solution { public: int sumIndicesWithKSetBits(vector<int>& nums,
阅读全文
摘要:1.题目介绍 2.题解 2.1 快排+遍历 思路 同本系列前几题一样 代码 class Solution { public: std::vector<int> singleNumber(std::vector<int>& nums) { int count = 0; std::vector<int>
阅读全文
摘要:1.题目介绍 2.题解 2.1 哈希表 思路 同本系列题I,不过多赘述 代码 class Solution { public: int singleNumber(std::vector<int>& nums) { std::unordered_map<int,int> map; for (int n
阅读全文