Skip to content

Commit a8c5f70

Browse files
committed
1799
1 parent b98b088 commit a8c5f70

File tree

1 file changed

+2
-2
lines changed
  • leetcode/1799. Maximize Score After N Operations

1 file changed

+2
-2
lines changed

leetcode/1799. Maximize Score After N Operations/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ public:
8888
int cnt = __builtin_popcount(m);
8989
if (cnt % 2) continue; // if there are even number of elements in this subset, skip
9090
vector<int> b; // indexes of elements in this subset
91-
for (int i = 0; i < 20; ++i) {
92-
if (m >> i & 1) b.push_back(i); // `m` is bit 1 at position `i`, which means that `A[i]` is in the current subset
91+
for (int tmp = m, i = 0; tmp; ++i, tmp >>= 1) {
92+
if (tmp & 1) b.push_back(i); // `m` has bit 1 at position `i`, which means that `A[i]` is in the current subset
9393
}
9494
for (int i = 0; i < b.size() ; ++i) {
9595
for (int j = i + 1; j < b.size(); ++j) { // use different pairs as the last operation on this subset

0 commit comments

Comments
 (0)