leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE |

commit0dc2bebb110f3e9c1e561c9ee1d7f8890543d389
parent38025ba13dc953105bf207696885e21cdd7d122d
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateMon, 20 May 2024 19:26:39 +0200

Daily Problem

Diffstat:
AProblems/1863.cpp|+++++++++++++++++++
MREADME.md|+

2 files changed, 20 insertions(+), 0 deletions(-)


diff --git a/Problems/1863.cpp b/Problems/1863.cpp

@@ -0,0 +1,19 @@

class Solution {
public:
int subsetXORSum(const vector<int> &nums) const {
const int n = size(nums);
int res = 0;
for (uint16_t mask = 1; mask < (1 << n); mask++) {
uint16_t crnt = mask, acc = 0;
while (crnt) {
const uint8_t idx = countr_zero(crnt);
acc ^= nums[idx];
crnt ^= 1 << idx;
}
res += acc;
}
return res;
}
};

diff --git a/README.md b/README.md

@@ -967,6 +967,7 @@ for solving problems.

| 1857 | Hard | [Largest Color Value in a Directed Graph](Problems/1857.cpp) |
| 1860 | Medium | [Incremental Memory Leak](Problems/1860.cpp) |
| 1861 | Medium | [Rotating the Box](Problems/1861.cpp) |
| 1863 | Easy | [Sum of All Subset XOR Totals](Problems/1863.cpp) |
| 1870 | Medium | [Minimum Speed to Arrive on Time](Problems/1870.cpp) |
| 1873 | Easy | [Calculate Special Bonus](Problems/1873.cpp) |
| 1877 | Medium | [Minimize Maximum Pair Sum in Array](Problems/1877.cpp) |