개발 로그/알고리즘
1863. Sum of All Subset XOR Totals.cpp
CyberSoak
2021. 10. 4. 16:44
난이도가 높아지니까, dp알고리즘 활용 문제가 자꾸 나온다 😕
//thanks to https://www.youtube.com/watch?v=CJ9EicV9nWc&ab_channel=CODE_CROSING
class Solution {
public:
int subsetXORSum(vector<int>& nums) {
return helper(nums, 0,0);
}
int helper(vector<int>&nums,int level, int currentXOR){
if(level == nums.size()) return currentXOR;
int inc = helper(nums,level +1,currentXOR^nums[level]);
int exc = helper(nums,level +1,currentXOR);
return inc + exc;
}
};