美文网首页
258. Add Digits

258. Add Digits

作者: 我是你的果果呀 | 来源:发表于2016-12-02 12:49 被阅读0次

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

    For example:

    Givennum = 38, the process is like:3 + 8 = 11,1 + 1 = 2. Since2has only one digit, return it.

    Follow up:

    Could you do it without any loop/recursion in O(1) runtime?

     /// 这个follow up 有点贱, 不是编程逻辑问题 纯数学问题, return 1+ (n-1)%9 ;  就酱!!! 别问我为什么, 如果面试出这个问题, 这人有点贱, 呵呵呵。

    正常解法很简单

    相关文章

      网友评论

          本文标题:258. Add Digits

          本文链接:https://www.haomeiwen.com/subject/idzfmttx.html