Run Time Beats 96.53%, Very Simple Java Solution


  • 0

    public class Solution {
    public boolean isHappy(int n) {
    if(n==1 || n==7) return true;
    if(n<10 && n!=1 && n!=7) return false;
    int sum=0;
    while(n>=10){
    sum+=(n%10)(n%10);
    n/=10;
    }
    sum+=(n%10)
    (n%10);
    return isHappy(sum);

    }
    

    }


Log in to reply
 

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