The problem description is very confusing


  • 0
    W

    "A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1."

    This description makes people think think that the numbers that "loop endlessly in a cycle which does not include 1" are also happy numbers.

    The part "or it loops endlessly in a cycle which does not include 1" should be put in another sentence saying that: unhappy numbers should be like: XXXX.


  • -2
    H
    class Solution(object):
        def isHappy(self, n):
            """
            :type n: int
            :rtype: bool
            """
            def index(n):
                if n < 7 and n != 1:
                     return False
                elif n == 1:
                     return True
                else:
                     sum1 = sum(map(lambda x:int(x)**2,str(n)))
                     return index(sum1)
            return index(n)

  • 0
    R

    I was confused at first and did not pay attention to the endless loop. I agree with you that if it adds some unhappy number examples , that would be better.


Log in to reply
 

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