fix(posts): fetch daily from files
This commit is contained in:
parent
3d2ee97afe
commit
2bcc3f4675
9 changed files with 691 additions and 0 deletions
16
public/code/algorithms/leetcode-daily/minend.cpp
Normal file
16
public/code/algorithms/leetcode-daily/minend.cpp
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
long long minEnd(int n, long long x) {
|
||||
int bits_to_distribute = n - 1;
|
||||
long long mask = 1;
|
||||
|
||||
while (bits_to_distribute > 0) {
|
||||
if ((x & mask) == 0) {
|
||||
// if the bit should be set, set it-otherwise, leave it alone
|
||||
if ((bits_to_distribute & 1) == 1)
|
||||
x |= mask;
|
||||
bits_to_distribute >>= 1;
|
||||
}
|
||||
mask <<= 1;
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue