Skip to content

Commit 26e4156

Browse files
committed
2081. Sum of k-Mirror Numbers: RETRY
1 parent f460bb3 commit 26e4156

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,3 +1570,4 @@ mod s2076_process_restricted_friend_requests;
15701570
mod s2078_two_furthest_houses_with_different_colors;
15711571
mod s2079_watering_plants;
15721572
mod s2080_range_frequency_queries;
1573+
mod s2081_sum_of_k_mirror_numbers;
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/**
2+
* [2081] Sum of k-Mirror Numbers
3+
*
4+
* A k-mirror number is a positive integer without leading zeros that reads the same both forward and backward in base-10 as well as in base-k.
5+
*
6+
* For example, 9 is a 2-mirror number. The representation of 9 in base-10 and base-2 are 9 and 1001 respectively, which read the same both forward and backward.
7+
* On the contrary, 4 is not a 2-mirror number. The representation of 4 in base-2 is 100, which does not read the same both forward and backward.
8+
*
9+
* Given the base k and the number n, return the sum of the n smallest k-mirror numbers.
10+
*
11+
* Example 1:
12+
*
13+
* Input: k = 2, n = 5
14+
* Output: 25
15+
* Explanation:
16+
* The 5 smallest 2-mirror numbers and their representations in base-2 are listed as follows:
17+
* base-10 base-2
18+
* 1 1
19+
* 3 11
20+
* 5 101
21+
* 7 111
22+
* 9 1001
23+
* Their sum = 1 + 3 + 5 + 7 + 9 = 25.
24+
*
25+
* Example 2:
26+
*
27+
* Input: k = 3, n = 7
28+
* Output: 499
29+
* Explanation:
30+
* The 7 smallest 3-mirror numbers are and their representations in base-3 are listed as follows:
31+
* base-10 base-3
32+
* 1 1
33+
* 2 2
34+
* 4 11
35+
* 8 22
36+
* 121 11111
37+
* 151 12121
38+
* 212 21212
39+
* Their sum = 1 + 2 + 4 + 8 + 121 + 151 + 212 = 499.
40+
*
41+
* Example 3:
42+
*
43+
* Input: k = 7, n = 17
44+
* Output: 20379000
45+
* Explanation: The 17 smallest 7-mirror numbers are:
46+
* 1, 2, 3, 4, 5, 6, 8, 121, 171, 242, 292, 16561, 65656, 2137312, 4602064, 6597956, 6958596
47+
*
48+
*
49+
* Constraints:
50+
*
51+
* 2 <= k <= 9
52+
* 1 <= n <= 30
53+
*
54+
*/
55+
pub struct Solution {}
56+
57+
// problem: https://leetcode.com/problems/sum-of-k-mirror-numbers/
58+
// discuss: https://leetcode.com/problems/sum-of-k-mirror-numbers/discuss/?currentPage=1&orderBy=most_votes&query=
59+
60+
// submission codes start here
61+
62+
impl Solution {
63+
pub fn k_mirror(k: i32, n: i32) -> i64 {
64+
0
65+
}
66+
}
67+
68+
// submission codes end
69+
70+
#[cfg(test)]
71+
mod tests {
72+
use super::*;
73+
74+
#[test]
75+
#[ignore]
76+
fn test_2081_example_1() {
77+
let k = 2;
78+
let n = 5;
79+
80+
let result = 25;
81+
82+
assert_eq!(Solution::k_mirror(k, n), result);
83+
}
84+
85+
#[test]
86+
#[ignore]
87+
fn test_2081_example_2() {
88+
let k = 3;
89+
let n = 7;
90+
91+
let result = 499;
92+
93+
assert_eq!(Solution::k_mirror(k, n), result);
94+
}
95+
96+
#[test]
97+
#[ignore]
98+
fn test_2081_example_3() {
99+
let k = 7;
100+
let n = 17;
101+
102+
let result = 20379000;
103+
104+
assert_eq!(Solution::k_mirror(k, n), result);
105+
}
106+
}

0 commit comments

Comments
 (0)