题目中明确说了 假如不是一直在1循环也是一直循环 所以就用检查环的那个方法
一个快指针移动两步 一个慢指针移动一步
public class Solution {
public boolean isHappy(int n) {
int slow = n;
int fast = n;
do {
slow = calc( slow );
fast = calc( fast );
fast = calc (fast);
}while ( fast != slow );
if ( fast == 1)
return true;
else
return false;
}
public int calc ( int n ){
int sum = 0;
while ( n != 0){
sum += (n % 10) * (n % 10);
n = n / 10;
}
return sum;
}
}