1837. Sum of Digits in Base K Easy
1/**
2 * [1837] Sum of Digits in Base K
3 *
4 * Given an integer n (in base 10) and a base k, return the sum of the digits of n after converting n from base 10 to base k.
5 * After converting, each digit should be interpreted as a base 10 number, and the sum should be returned in base 10.
6 *
7 * Example 1:
8 *
9 * Input: n = 34, k = 6
10 * Output: 9
11 * Explanation: 34 (base 10) expressed in base 6 is 54. 5 + 4 = 9.
12 *
13 * Example 2:
14 *
15 * Input: n = 10, k = 10
16 * Output: 1
17 * Explanation: n is already in base 10. 1 + 0 = 1.
18 *
19 *
20 * Constraints:
21 *
22 * 1 <= n <= 100
23 * 2 <= k <= 10
24 *
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/sum-of-digits-in-base-k/
29// discuss: https://leetcode.com/problems/sum-of-digits-in-base-k/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34 pub fn sum_base(n: i32, k: i32) -> i32 {
35 0
36 }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn test_1837() {
47 }
48}
49
Back
© 2025 bowen.ge All Rights Reserved.