-
23. Add DigitsProblem Solving 2022. 9. 13. 08:59728x90
https://leetcode.com/problems/add-digits/
Add Digits - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
한 자릿수가 될 때까지 각각의 자릿수를 계속 더하는 문제
class Solution: def addDigits(self, num: int) -> int: digits = str(num) add = 0 while True: add = 0 for i in digits: add = add + int(i) digits = str(add) if len(str(add)) == 1: break return add
반복문 두 개 써서 submit이 안 될 줄 알았음 하하
'Problem Solving' 카테고리의 다른 글
25. Power of Four (0) 2022.09.15 24. Lemonade Change (0) 2022.09.14 22. 핸드폰 요금 (0) 2022.09.12 21. 플러그 (0) 2022.09.12 20. 지능형 기차 (0) 2022.09.12