python学习之——Add Digits

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.

For example:

Given num = 38, the process is like: 3 + 8 = 111 + 1 = 2. Since 2 has only one digit, return it.

思路:取各位数字相加,直至相加结果为一位数(<9),考虑边界情况

思路:规律是直接与9的取余

原文地址:https://www.cnblogs.com/cloverclt/p/4757590.html