EASIEST JAVA SOLUTION


  • -1
    A
    public boolean isHappy(int n) {
        if(n==1){
            return true;
        }
        int num = 0;
        while(n>6){
            while(n>0){
                num += (n%10) * (n%10); 
                n /= 10; 
            }
            n = num; // 16
            num = 0; 
        }
        return n==1;
    }

Log in to reply
 

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