随笔分类 - 位运算
摘要:link class Solution { public: int longestAwesome(string s) { int n=s.size(); vector<int> dp(1<<10,n); int res=1; dp[0]=-1; int mask=0; for(int i=0;i<n
阅读全文
摘要:link 每一位1的个数有三种状态,0,1,2,3(0) 用两个bit,low和high来记录这些状态。 class Solution { public: int singleNumber(vector<int>& nums) { int high=0; int low=0; for(int n:n
阅读全文
摘要:link a b 相等等价于 a^b=0. 则问题转换为找一对i,j a[i]^...^a[j]=0. class Solution { public: int countTriplets(vector<int>& arr) { int n=arr.size(); vector<int> pre(n
阅读全文
摘要:class Solution { public: vector<int> singleNumbers(vector<int>& nums) { int total=0; for(int i:nums) total^=i; int one=1; while((one&total)==0) one<<=
阅读全文

浙公网安备 33010602011771号