Skip to content

Commit 13a11ed

Browse files
authored
Create 3133. Minimum Array End (#630)
2 parents 95c1c5e + db77f73 commit 13a11ed

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

3133. Minimum Array End

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
long long minEnd(int n, int x) {
4+
long long res = x;
5+
long long i_x = 1;
6+
long long i_n = 1;
7+
8+
while (i_n <= n - 0) {
9+
if ((i_x & x) == 0) {
10+
res |= i_x * (i_n & (n - 1) ? 1 : 0);
11+
12+
i_n <<= 1;
13+
}
14+
i_x <<= 1;
15+
}
16+
17+
return res;
18+
}
19+
};

0 commit comments

Comments
 (0)