cmfr 发表于 2015-12-2 15:04:12

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 = 11, 1 + 1 = 2. Since 2 has only one digit, return it.
  思路:取各位数字相加,直至相加结果为一位数(<9),考虑边界情况

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

  
页: [1]
查看完整版本: python学习之——Add Digits