File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change 1+ def sumBase (n : int , k : int ) :
2+ """
3+ 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.
4+ After converting, each digit should be interpreted as a base 10 number, and the sum should be returned in base 10.
5+ TC : O(N)
6+ SC : O(1)
7+ n : int (integer base 10)
8+ k : int (base to be converted to)
9+ return value : int
10+ """
11+ summation = 0
12+ while n >= k :
13+
14+ summation = summation + n % k
15+ n = n // k
16+ print (n )
17+ return (summation + n )
Original file line number Diff line number Diff line change @@ -321,6 +321,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
321321| 1518 | [ Water Bottles] ( https://leetcode.com/problems/water-bottles/ ) | [ Java] ( ./Java/WaterBottles.java ) | _ O(n)_ | _ O(n)_ | Easy | Math | |
322322| 1822 | [ Sign Of Product] ( https://leetcode.com/problems/sign-of-the-product-of-an-array/ ) | [ Java] ( ./Java/SignOf.java ) | _ O(n)_ | _ O(n)_ | Easy | Math | |
323323| 991 | [ Broken Calculator] ( https://leetcode.com/problems/broken-calculator/ ) | [ Java] ( ./Java/BrokenCalculator.java ) | _ O(n)_ | _ O(n)_ | Medium | Math | |
324+ | 1837 | [ Sum of Digits in Base K] ( https://leetcode.com/problems/sum-of-digits-in-base-k/ ) | [ Python] ( ./Python/baseK.py ) | _ O(n)_ | _ O(1)_ | Easy | Math | |
324325
325326<br />
326327<div align =" right " >
You can’t perform that action at this time.
0 commit comments