All numbers will fall into 1 or 4, can anyone prove it. 1ms Java Solution


  • 0
    I
    public boolean isHappy(int n) {
            while(n!=1&&n!=4){
                int res = 0;
                while(n>0){
                    int r = n%10;
                    res+=r*r;
                    n=n/10;
                }
                n=res;
            }
            if(n==1) return true;
            else return false;
        }

Log in to reply
 

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