Solution for Add Digits


  • 1
    N
    public class Solution {
        public int addDigits(int num) {
            return num/10==0?num:addDigits(num%10 + addDigits(num/10));
        }
    }

  • 0
    N

    Sorry, I missed the follow up which says without loop or recursion. This solution took 2ms. Will update this solution


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.