您好,欢迎来到要发发知识网。
搜索
您的当前位置:首页python学习之——Add Digits

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

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- net188.cn 版权所有 湘ICP备2022005869号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务