Minimum Runtime C++ Solution


  • 0
    R

    The happy number ends in 1 process does not exceed 6 steps.
    For example:
    bool isHappy(int n) {
    int sum=0;
    int s=0;
    while(n!=1){
    while(n!=0){
    sum+=(n%10)*(n%10);
    n=n/10;
    }
    n=sum;
    sum=0;
    s++;
    if(s>6){
    return false;
    }
    }
    return true;
    }


Log in to reply
 

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