Class Solution
java.lang.Object
g1801_1900.s1837_sum_of_digits_in_base_k.Solution
1837 - Sum of Digits in Base K.<p>Easy</p>
<p>Given an integer <code>n</code> (in base <code>10</code>) and a base <code>k</code>, return <em>the <strong>sum</strong> of the digits of</em> <code>n</code> <em><strong>after</strong> converting</em> <code>n</code> <em>from base</em> <code>10</code> <em>to base</em> <code>k</code>.</p>
<p>After converting, each digit should be interpreted as a base <code>10</code> number, and the sum should be returned in base <code>10</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> n = 34, k = 6</p>
<p><strong>Output:</strong> 9</p>
<p><strong>Explanation:</strong> 34 (base 10) expressed in base 6 is 54. 5 + 4 = 9.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> n = 10, k = 10</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong> n is already in base 10. 1 + 0 = 1.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= n <= 100</code></li>
<li><code>2 <= k <= 10</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
sumBase
public int sumBase(int n, int k)
-