Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3811d19

Browse files
Basek python (#235)
* added Leetcode #1837 * repaired indent error * Update README.md
1 parent 34821d1 commit 3811d19

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

‎Python/baseK.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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)

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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">

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /