Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 48da323

Browse files
authoredDec 27, 2020
Update minimum-adjacent-swaps-for-k-consecutive-ones.cpp
1 parent 2035581 commit 48da323

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed
 

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ 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)); // take each i+k//2 as median, find min dist to median
22+
result = min(result, -score(i, i + k / 2 - 1) + score(i + (k + 1) / 2, i + k - 1)); // take each i+k//2 as median, find min dist to median
2323
}
2424
result -= (k / 2) * ((k + 1) / 2); // rollback extra moves to the expected positions
2525
return result;

0 commit comments

Comments
 (0)
Please sign in to comment.