Skip to content

Commit 794dcb3

Browse files
authored
Update sum-of-k-mirror-numbers.cpp
1 parent 999b3d5 commit 794dcb3

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ class Solution {
66
long long kMirror(int k, int n) {
77
const int base1 = k, base2 = 10; // (10, k) is slower
88
int64_t result = 0;
9-
vector<int> prefix_num(2, 1), cnt(2), total(2, base1 - 1);
9+
vector<int> prefix_num(2, 1), total(2, base1);
1010
uint8_t odd = 1;
1111
while (n--) {
1212
int64_t x;
1313
do {
14-
x = mirror(prefix_num[odd]++, base1, odd);
15-
if (++cnt[odd] == total[odd]) {
16-
cnt[odd] = 0;
14+
x = mirror(prefix_num[odd], base1, odd);
15+
if (++prefix_num[odd] == total[odd]) {
1716
total[odd] *= base1;
1817
odd ^= 1;
1918
}

0 commit comments

Comments
 (0)