202. Happy Number

public class Solution {
    public boolean isHappy(int n) {
        boolean res=false;
        Map<Integer,Integer> mp=new HashMap<Integer,Integer>();
        int temp=n;
        while(true)
        {
            int sum=0;
            while(temp!=0)
            {
                sum+=(temp%10)*(temp%10);
                temp/=10;
            }
            
            if(sum==1)
            {
                return true;
            }
            if(mp.containsKey(sum))
            {
                return false;
            }
            else
            {
                mp.put(sum,1);
                temp=sum;
            }

        }
    }
}
原文地址:https://www.cnblogs.com/aguai1992/p/5349297.html