Problem Solving/LeetCode
2023.04.26 Today's Challenge
fabichoi
2023. 4. 26. 23:45
https://leetcode.com/problems/add-digits/
Add Digits - LeetCode
Can you solve this real interview question? Add Digits - Given an integer num, repeatedly add all its digits until the result has only one digit, and return it. Example 1: Input: num = 38 Output: 2 Explanation: The process is 38 --> 3 + 8 --> 11 11 -->
leetcode.com
class Solution:
def addDigits(self, num: int) -> int:
return 1 + (num - 1) % 9 if num else 0
반응형