Skip to content

Commit c3dfcd8

Browse files
solves add digits in python
1 parent 0df8517 commit c3dfcd8

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
| 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | Easy | |
7979
| 256 | 🔒 [Paint House](https://leetcode.com/problems/paint-house) | Easy | |
8080
| 257 | [Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BinaryTreePaths.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/binary_tree_paths.py) |
81-
| 258 | [Add Digits](https://leetcode.com/problems/add-digits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddDigits.java) |
81+
| 258 | [Add Digits](https://leetcode.com/problems/add-digits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddDigits.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_digits.py) |
8282
| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/UglyNumber.java) |
8383
| 266 | [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | Easy | |
8484
| 268 | [Missing Number](https://leetcode.com/problems/missing-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MissingNumber.java) |

python/add_digits.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution:
2+
def addDigits(self, num: int) -> int:
3+
number_str = str(num)
4+
if len(number_str) == 1:
5+
return num
6+
return self.addDigits(sum(int(digit) for digit in number_str))

0 commit comments

Comments
 (0)