Skip to content

Commit 2035581

Browse files
authored
Update minimum-adjacent-swaps-for-k-consecutive-ones.cpp
1 parent 29a7840 commit 2035581

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

C++/minimum-adjacent-swaps-for-k-consecutive-ones.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class Solution {
1919
};
2020
uint64_t result = numeric_limits<uint64_t>::max();
2121
for (int i = 0; i < size(idxs) - k + 1; ++i) {
22-
result = min(result, -score(i, i + (k + 1) / 2 - 1) + score(i + k / 2, i + k - 1));
22+
result = min(result, -score(i, i + (k + 1) / 2 - 1) + score(i + k / 2, i + k - 1)); // take each i+k//2 as median, find min dist to median
2323
}
24-
result -= (k / 2) * ((k + 1) / 2);
24+
result -= (k / 2) * ((k + 1) / 2); // rollback extra moves to the expected positions
2525
return result;
2626
}
2727
};

0 commit comments

Comments
 (0)