0 ms Java solution


  • 0
    1
        public boolean isHappy(int n) {
            int num = n;
            int count = 0;
            while (num != 1)
            {
                count++;
                if (count > 100) return false;
                int sum = 0;
                while (num != 0)
                {
                    int a = num%10;
                    sum += Math.pow(a, 2);
                    num /= 10;
                }
                num = sum;
            }
            return true;
        }
    }

  • 0
    J

    测了一下,13ms...


Log in to reply
 

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