The 1ms java solution


  • 1
    F

    this is my solution:

    public class Solution {
        public int addDigits(int num) {
    		if (num == 0)
    			return 0;
    		int temp = num%9;
    		if (temp == 0)
    			return 9;
    		return temp;
        }
    }
    

    it cost 2ms.Does anyone know the 1ms solution?

    thanks.


Log in to reply
 

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