Skip to content

Commit 61ba594

Browse files
authored
Update sum-of-k-mirror-numbers.cpp
1 parent 767ab68 commit 61ba594

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

C++/sum-of-k-mirror-numbers.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ class Solution {
77
const int base1 = k, base2 = 10; // (10, k) is slower
88
int64_t result = 0;
99
vector<int> prefix_num(2, 1), cnt(2), total(2, base1 - 1);
10-
bool even = false;
10+
uint8_t odd = 1;
1111
while (n--) {
1212
int64_t x;
1313
do {
14-
x = mirror(prefix_num[even]++, base1, even);
15-
if (++cnt[even] == total[even]) {
16-
cnt[even] = 0;
17-
total[even] *= base1;
18-
even = !even;
14+
x = mirror(prefix_num[odd]++, base1, odd);
15+
if (++cnt[odd] == total[odd]) {
16+
cnt[odd] = 0;
17+
total[odd] *= base1;
18+
odd ^= 1;
1919
}
2020
} while (x != reverse(x, base2));
2121
result += x;
@@ -24,9 +24,9 @@ class Solution {
2424
}
2525

2626
private:
27-
int64_t mirror(int n, int base, bool even) {
27+
int64_t mirror(int n, int base, bool odd) {
2828
int64_t result = n;
29-
if (!even) {
29+
if (odd) {
3030
n /= base;
3131
}
3232
for (; n; n /= base) {

0 commit comments

Comments
 (0)