package com.fishercoder.solutions;

/**
 * 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.

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

 Hint:

 A naive implementation of the above process is trivial. Could you come up with other methods?
 What are all the possible results?
 How do they occur, periodically or randomly?
 You may find this Wikipedia article: https://en.wikipedia.org/wiki/Digital_root useful.
 * */

public class _258 {

    //only three cases as the code shows
    public int addDigits(int num) {
        if (num == 0) {
            return 0;
        }
        if (num % 9 == 0) {
            return 9;
        }
        return num % 9;
    }

}

@@ -33,609 +33,69 @@
 s;%0A%0A
-/**%0A * Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.%0A%0A For example:%0A%0A Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it.%0A%0A Follow up:%0A Could you do it without any loop/recursion in O(1) runtime?%0A%0A Hint:%0A%0A A naive implementation of the above process is trivial. Could you come up with other methods?%0A What are all the possible results?%0A How do they occur, periodically or randomly?%0A You may find this Wikipedia article: https://en.wikipedia.org/wiki/Digital_root useful.%0A * */%0A%0Apublic class _258 %7B%0A%0A
+public class _258 %7B%0A%0A    public static class Solution1 %7B%0A    
     
@@ -131,24 +131,28 @@
 e shows%0A    
+   
+ 
 public int a
@@ -167,24 +167,28 @@
 (int num) %7B%0A
+    
         if (
@@ -207,24 +207,28 @@
             
+    
 return 0;%0A  
@@ -225,34 +225,42 @@
 turn 0;%0A        
+ 
-%7D%0A
+   %7D%0A    
         if (num 
@@ -279,24 +279,28 @@
             
+  
+  
 return 9;%0A  
@@ -297,34 +297,42 @@
 turn 9;%0A        
-%7D%0A
+    %7D%0A    
         return n
@@ -343,13 +343,22 @@
  9;%0A    
+    %7D%0A    
 %7D
-%0A
 %0A%7D%0A

refactor 258