add: 220315-CN [cpp]
This commit is contained in:
parent
74049b8dff
commit
aaa07a75df
|
|
@ -0,0 +1,18 @@
|
|||
#include <vector>
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
static int countMaxOrSubsets(const std::vector<int>& nums) {
|
||||
int maxOr = 0;
|
||||
for (int i : nums)
|
||||
maxOr |= i;
|
||||
int n = nums.size(), LIM = 1 << n, ret = 0;
|
||||
for (int i = 1; i < LIM; ++i) {
|
||||
int ans = 0;
|
||||
for (int j = 0; j < n; ++j)
|
||||
ans |= ((1 << j) & i) ? nums[j] : 0;
|
||||
ret += ans == maxOr;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
|
@ -3,4 +3,4 @@ PROJECT(2203)
|
|||
|
||||
SET(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
ADD_EXECUTABLE(2203 220314-CN.cpp)
|
||||
ADD_EXECUTABLE(2203 220315-CN.cpp)
|
||||
|
|
|
|||
Loading…
Reference in New Issue