1 ms in Java


  • 0
    T

    finally, it will be less 10.

    public class Solution {
        public boolean isHappy(int n) {
            if( n < 10 )
                return n==1 || n==7 ? true : false;
            else {
                int res = 0;
                while( n != 0 ) {
                    res += (n%10) * (n%10);
                    n /= 10;
                }
                return isHappy(res);
            }
        }
    }
    

Log in to reply
 

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