package hashTable;

/**
 * Created by cuixiaodao on 11/04/2017
 * for leetCode problem:
 * https://leetcode.com/problems/island-perimeter/description/
 */

public class HappyNumber {
    public boolean isHappy(int n) {
        int slow = getDigitSum(n), fast = getDigitSum(getDigitSum(n));
        while (slow != fast) {
            slow = getDigitSum(n);
            fast = getDigitSum(getDigitSum(n));
        }
        return slow == 1;
    }

    private int getDigitSum(int n) {
        int s = 0, r = 0;
        while (n != 0) {
            r = n % 10;
            n = n / 10;
            s += r * r;
        }
        return s;
    }
}

@@ -224,70 +224,30 @@
     
-int slow = getDigitSum(n), fast = getDigitSum(getDigitSum(n));
+// %E9%80%9A%E8%BF%87slow, fast%E6%9D%A5%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E6%88%90%E7%8E%AF
 %0A   
@@ -255,28 +255,42 @@
     
-while (
+int 
 slow 
-!
 =
+ n,
  fast
-)
+ = n;%0A        do
  %7B%0A 
@@ -319,17 +319,20 @@
 igitSum(
-n
+slow
 );%0A     
@@ -369,17 +369,20 @@
 igitSum(
-n
+fast
 ));%0A    
@@ -378,32 +378,68 @@
 ast));%0A        %7D
+ while (slow != fast && fast != 1);%0A
 %0A        return 
@@ -438,20 +438,20 @@
  return 
-slow
+fast
  == 1;%0A 
@@ -626,16 +626,16 @@
       %7D%0A
-
         
@@ -649,11 +649,151 @@
 s;%0A    %7D
+%0A%0A    public static void main(String%5B%5D args) %7B%0A        HappyNumber hn = new HappyNumber();%0A        System.out.println(hn.isHappy(19));%0A    %7D
 %0A%7D%0A

Update HappyNumber.java